Now I want to also get all of my superior data on users to the superior, but there are primary empty won't display, bosses how to write, please
CodePudding user response:
You can refer to the mysql recursive query:SELECT ID level, DATA. * FROM (
SELECT
@ ids as _ids,
(SELECT @ ids:=GROUP_CONCAT (id)
The FROM table1
WHERE FIND_IN_SET (parent_id, @ ids)
) as cids,
@ : l=@ l + 1 as level
The FROM table1,
(SELECT @ ids:='1', @ : l=0) b
WHERE @ ids IS NOT NULL
Table1) id DATA
WHERE FIND_IN_SET (DATA. Id, id. _ids)
The ORDER BY level, id