Home > database >  About the name of the table lookup recursive directory paths in question
About the name of the table lookup recursive directory paths in question

Time:09-29

Mysql path. How to extract the menu inside the root directory parent node PARENT_ID is null, the other parent node ID on the PARENT_ID is a node ID of the data,
Eventually need to generate the root directory & gt; One level & gt; The secondary directory & gt; Three directories & gt; .> The bottom directory

Such as table: TABLE_A
Fields: ID, NAME, PARENT_ID
1 the root directory null
2 one level 1
4 secondary directory 2
10 three directories 4
12 directory the bottom 10

CodePudding user response:

http://blog.csdn.net/qq12547345/article/details/72630285
You can refer to the man's blog,
Using the function find_in_set

CodePudding user response:

 SELECT @ v FROM (
SELECT @ v:=CONCAT_WS (' & gt; ', SELECT the NAME FROM TABLE_A WHERE PARENT_ID & lt;=> @ id) as v,
@ id:=(SELECT id FROM TABLE_A WHERE PARENT_ID & lt;=> @ id)
The FROM TABLE_A A, (SELECT @ v:=null, @ id:=null) _r
) A LIMIT 1
  • Related