I have this table.
I want to select cat id = 4 and every other row its cat parent id equals to.
e.g. if I want all categories from cat id 4, it should result to cat ids 4 (itself), 2 and 1
+-------------------------------+
| id | catname | catparentid |
+-------------------------------+
|1 | home | 0 |
|2 | products | 1 |
|3 | men | 2 |
|4 | women | 2 |
|5 | shirts | 3 |
|6 | outdoor | 0 |
+-------------------------------+
I tried:
SELECT * FROM categories c
where c.id = 4
c.catparentid IN (SELECT id FROM categories)
But it brings up all. Do I need to do a union?
1 Answer