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
As pointed out above this isn’t truly recursive but if you know how many steps deep you need to go as a maximum, you can use something along these lines (perhaps use PHP to generate the query):
I’d first set parent ID to NULL rather than 0, but that’s personal preference.
^^ however deep you need to go in that case.
[next bit not strictly relevant]
You can then manipulate the output something along these lines: