I have a table with tree data as it defined in this question and have to implement traversal of the tree that looks like preorder traversal but instead of root --> left subtree --> right subtree should be root --> 1-st subtree --> 2-nd subtree --> 3-rd subtree --> ... where order of subtrees is controlled by column SortOrder that displays 'local' order. For example if we have following data
id parentId sortOrder
----------------------------
1 NULL 1
2 NULL 2
3 1 1
4 1 2
5 NULL 3
6 3 1
7 5 1
the resulted order should be 1-3-6-4-2-5-7