Having a tree structure in database (id, parentId, order) where order means some value to sort per parent (it means order in parent list), how one can build full-SQL query to traverse this table in POST-ORDER?
What is post order is described on wiki, though only for binary trees - https://en.wikipedia.org/wiki/Tree_traversal
Not all of them is applyable to custom tree (for example IN-ORDER), but POST-ORDER is actully applyable:
A
/ \
B C
/|\
D E F
output will be:
B D E F C A
The same in SQL data table:
|Id |ParentId | Order
|___|_________|______
|A |null |0
|B |A |0
|C |A |1
|D |C |0
|E |C |1
|F |C |2
I have been struggling with it quite a time, but looks like CTE doesn't allow inner ORDER BY clause (omg, why?!), so this task becomes impossible at my current level without stored procedures.