I have written a CTE query and this is the result I am getting
Item Parent Level Group
--------------------------------------
CRSM/002 NULL 0 CRSM/002
7160/002 CRSM/002 1 CRSM/002
7823/085 CRSM/002 1 CRSM/002
7864/038 CRSM/002 1 CRSM/002
A543/033 CRSM/002 1 CRSM/002
7460/530 CRSM/002 1 CRSM/002
7280/007 7160/002 2 CRSM/002
7009/130 7160/002 2 CRSM/002
7567/001 7160/002 2 CRSM/002
7009/126 7160/002 2 CRSM/002
7280/003 7160/002 2 CRSM/002
7280/008 7160/002 2 CRSM/002
7280/005 7160/002 2 CRSM/002
7574/004 7160/002 2 CRSM/002
7280/004 7160/002 2 CRSM/002
7280/006 7160/002 2 CRSM/002
7454/224 7280/006 3 CRSM/002
7093/633 7280/006 3 CRSM/002
7202/010 7280/006 3 CRSM/002
7202/013 7280/004 3 CRSM/002
7454/253 7280/004 3 CRSM/002
7093/553 7280/005 3 CRSM/002
8865/957 7280/005 3 CRSM/002
7202/012 7280/005 3 CRSM/002
7093/696 7280/008 3 CRSM/002
7202/011 7280/008 3 CRSM/002
7454/294 7280/008 3 CRSM/002
7202/009 7280/003 3 CRSM/002
7454/201 7280/003 3 CRSM/002
7656/002 7009/126 3 CRSM/002
A556/075 7009/126 3 CRSM/002
7574/002 7009/126 3 CRSM/002
A902/027 7009/126 3 CRSM/002
7093/418 7280/007 3 CRSM/002
7454/245 7280/007 3 CRSM/002
7202/008 7280/007 3 CRSM/002
It is returning proper data with all the levels of hierarchy, parent child relation and root level parent grouping.
The data is coming correct but I want data to be arranged in tree structure, meaning currently the arrangement is like this level 0 row first and then all the element with level 1 row and so.. on..
What I want the arrangement to be is, 0 level first and then 1st level 1st child and if that child has children then those children which will be in second level and etc. So it will become the actual tree structure. I don't know if I was able to explain my problem properly or not. I have tried ordering and other combinations but couldn't get success.
Is there any way?