How to Display parent Child in specific order by using sql query
Suppose,I have table in which i have two columns one is parent id a开发者_开发知识库nd onother is child id and child can be parent of another child and so on.......something like this
Parent id Child id p1 c1 c1 c2 p1 c3 c1 c4 p3 c5 p3 c6 c4 c7 c5 c8
i am trying to write a query which gives me output like this.......
Parent id Child id p1 c1 p1 c3 c1 c2 c1 c4 c4 c7 p3 c5 p3 c6 c5 c8 c8 ..................and so on.....
Guys please help me out... Thanks in advance....
If I understand it correctly, you need parents before children and children ordered within each parent ( are you building some kind of tree structure in you application?)
Simple
SELECT *
FROM Table
ORDER BY ParentID, ChildID
should do the trick.
精彩评论