I have a category table with id,name,parentid.
id------name------parentid
1 a 0
2 b 0
3 c 1
4 d 1
5 e 2
6 f 2
7 g 2
8 h 2
9 i 0
I want a single query to display the result in the following format:
1---a
3---c
4---d
2---b
5---e
6---f
OK this will only work if you’ve less than 10,000 children per parent, and will only work for two levels i.e. parent has child, but not child has child.
Also, this is general SQL, don’t know if it’ll work for mysql
Hope this helps