I want to fetch all the child ids (comma separeted) but my code just getting the two level heirachy, not more than that. I dont know whats issue? here is my code
select concat (a.id,',',a.parent_id) as parents
from table1 a
inner join table1 b
on a.id = b.parent_id
where b.id = 5
Here is my table structure:
id | parent_id
---------------------
1 | 6
2 | NULL
3 | 1
4 | 3
5 | 4
6 | NULL
7 | NULL
output expected:
4,3,1,6