Here is what I have in my MySQL DB table:
id | parent | name
----------------------
1 | null | Root 1
3 | null | Root 3
6 | 3 | something 1
7 | 6 | something 2
9 | 1 | something 3
I would like to get the most recent branch out of the table. Right now I just check for highest id
and follow the items to the root in code.
In my case I can assume the latest entry is always the tip of a branch and not the middle of a branch or a root.
The problem I have is to get the newest of a specific root. So let's say I want the latest branch of root 3
. How would I do that?
Is there a way I can query for this in SQL without having to do recursive loops in PHP until I find what I need?
Changing the way the tree is stored in SQL is not an option at this time. :(