column view
+-----------------------+
| name |
+-----------------------+
| ELECTRONICS |
| TELEVISIONS |
| TUBE |
| LCD |
| PLASMA |
| GAME CONSOLES |
| PORTABLE ELECTRONICS |
| MP3 PLAYERS |
| FLASH |
| CD PLAYERS |
| 2 WAY RADIOS |
| FRS |
+-----------------------+
table core.category
Id ParentId Name
1 null ELECTRONICS
2 1 TELEVISIONS
3 2 TUBE
4 2 LCD
5 2 PLASMA
6 1 GAME CONSOLES
7 1 PORTABLE ELECTRONICS
8 7 MP3 PLAYERS
9 8 FLASH
10 7 CD PLAYERS
11 1 2 WAY RADIOS
12 11 FRS
If I SELECT 1,
result is (shows children and grandchildren) expect that there is more than 1 grandparent(ELECTRONICS)
+-----+
| id |
+-----+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
| 10 |
| 11 |
| 12 |
+-----+
If I select 2
result must be
+-----+
| id |
+-----+
| 2 |
| 3 |
| 4 |
| 5 |
+-----+
i got this for selected category and his children ( need more to output grandchildren)
module.exports.categorySearch = function(searchCategory, cb) {
var query = 'SELECT category_id \
FROM core.category AS c \
WHERE category_id = $1::integer
UNION
SELECT category_id \
FROM core.category AS c \
WHERE category_ParentId = $1::integer
;';
var map = function(err, result) {
if(err) {
return cb(err, null);
}
var list = [];
result.rows.forEach(function(row, i) {
list.push(new Category(row));
});
cb(null, list);
};
repository.queryDb(query, [searchCategory], map);
};
result is
+-----+
| id |
+-----+
| 1 |
| 2 |
| 6 |
| 7 |
| 11 |
+-----+
what should i add to my select statement