php - Parent - Child relationship within a single table -
I have a table which is like the following. Let me establish the original child relationship between rows in this single table is required. I need to get the parents in the reverse order up to level 4 . For example, the last record uid 10007 whose parent 10005 is now the parent of uid 10005 10004 and 10004 parents 10002 and Parents> 10002 is 10001 . I am using MySQL so it does not seem to be possible. What options do I have and how can I address this multi-level problem. I use PHP / MySQL Thank you in advance. from you. A finite 4 levels, you should not have a recursive requirement (though it will be easy to be able to use such MS SQL CTE) Like: If you need to do this for several nodes, then you have to get involved in anything that is choosing your initial nodes, or above the example if it was done with freehand then misspelled apologies. parentid uid 10001 10001 10001 10002 10001 10003 10002 10004 10004 10005 10003 10006 10005 10007
Select t4.uid as a child, as the parent --t3.uid grand_parent as --t2.uid, great_great_grand_parent, great_grand_parent as --t1.uid t1.parentid from your_table_name inner t2.parentid = t1 Join your_table_name t2 on .uid T1 your start node - inner t3.parentid = t2.uid joining your_table_name t3 on inner t4.parentid = T3.uin where your_table_name on t4.uid = '10007' is included in T-4.
WHERE t4. Uid = 10007 ' to be the section
where in t4.uid (select uid separately from your_table_name)
Comments
Post a Comment