Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a table with parent child relation I want help on recursive query

Table structure

roleId,  roleName,      parentId
1        Admin          0
2        Backup Admin   1
3        Office User 1  0
4        User 1         3
5        User 2         3
6        Office User 2  0
7        Off User 1     6

I am trying to make recursive query but I am not able to do please suggest me how should I query database e.g.

  Admin
  -- Backup Admin
  Office User 1
  -- User 1
  -- User 2
  Office User 2
  -- Off User 1
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
326 views
Welcome To Ask or Share your Answers For Others

1 Answer

Query the table once, getting all the names and IDs, then construct the tree in whatever programming language you're using.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...