Selecting records in order of parent id

前端 未结 4 890
天涯浪人
天涯浪人 2020-12-31 17:14

Simple question.. just can\'t get the result set in the order I need :p

I have a table \"categories\"

id    | name     | parent
1       apple      0
         


        
4条回答
  •  独厮守ぢ
    2020-12-31 17:52

    See if this works:

    SELECT Table1.ID, Table1.name, Table1.parent, Table1_1.name, Table1_1.parent
    FROM Table1 INNER JOIN Table1 AS Table1_1 ON Table1.ID = Table1_1.parent
    ORDER BY Table1.name;
    

    I built this with Micorsoft Access and it looked like what you wanted to me. I think you need a report to group on to visually give you what you want to give to a consumer, but for the sake joining correctly to get to that point this works.

提交回复
热议问题