I am looking for a non-recursive solution to make a MySQL query to select all of the leaf nodes (children, grandchildren etc) of a node while only knowing who the direct child of the node is.
Currently I have the following tables:
Nodes:
- id (INT)
- data (VARCHAR)
Relationships:
- parentId (INT)
- childId (INT)
- childNodeOrder (INT)
The way I have it currently I can only select the direct child nodes of a parent node (for this example let the parent Id = 1):
SELECT * FROM Nodes n
JOIN Relationships r ON r.childId = n.id
WHERE r.parentId = 1
ORDER BY r.childNodeOrder;
Is there any way for me to change this database around easily to not use a recursive call (on my server side code) and to be able to get all of the descendant leaves of a parent?
I so far have looked at questions like this one which would seem like a radical change, and not very easy to switch over...