Get all parents for a child

后端 未结 3 1391
春和景丽
春和景丽 2020-12-14 16:50

I want to retrieve the parentid of an id, if that parentid has a parent again retrieve it, and so on. Kind of hierarchy table.

id----parentid
1-----1
5-----1         


        
3条回答
  •  忘掉有多难
    2020-12-14 17:14

    Your query is doing recursion but in opposite direction. So if you change starting point to:

    where id = 1
    

    then you will have user 1 and all his successors

提交回复
热议问题