I have implemented the following hierarchical data using MySQL
1
|----- 2
|----- 3
4
|----- 5
|----- 6
|----- 7
id | path | level | parent_id | content |
-------------------------------------------------------------------
1 1 1 NULL xxx
2 1:2 2 1 yyy
3 1:3 2 1 abc
4 4 1 NULL zzz
5 4:5 2 4 yyy
6 4:6 2 4 abc
7 4:6:7 3 6 abc
Assuming I have only these records, how do I retrieve them in a tree structure and yet within a single collection starting with the last tree?
What I expected from the query or stored procedure is to return me the following in exactly this order
id
-----
4
5
6
7
1
2
3
How do I do the same but starting with the first tree?
id
-----
1
2
3
4
5
6
7