Can anyone guide me on how to create the lft and rgt columns (parsed from left to right in a tree from root)dynamically for a table using MySQL Query?
The structure of my table looks like this:
id----name----parent_id
and I want the structure like this :
name----lft----rgt
You can self-join the table and aggregate:
This assumes exactly two children per node. If some nodes may have one child only, you can add a little logic: