0

I have a table (master_tree) that contains the following structure:

rid - Autoincrement
parent_id
child_id
side_to_parent
level_in_tree
creation_date

select level_in_tree,count(*) from (select child_id, level_in_tree from master_tree, (select @pv := 2) initialisation where find_in_set(parent_id, @pv) > 0 and @pv := concat(@pv, ',', child_id)) as temp group by level_in_tree

The above query returns the number of child on a level. I need to traverse the tree left to right on a particular level but the issue is I don't know which child is the first on that level and which is last on every particular level. I need to attach a child on the level wherever the first time its gets node empty.

I need to generate a query in Mysql. I don't want to add recursion in PHP that causes a lot of delays.

enter image description here

I dont want to get the childs of whole tree. I want to get the first empty position from referral where new child can be added

Amanjot Kaur
  • 2,028
  • 4
  • 18
  • 33

0 Answers0