I'm trying to understand how MySQL recursive queries work and to get the data the way I want it.
Right now I have the following SQL
SELECT `Library`.*, l2.*, l3.*
FROM `Library`
LEFT JOIN `Library` as `l2` on `l2`.`subsectionOf`=`Library`.`iD`
LEFT JOIN `Library` as `l3` on `l3`.`subsectionOf`=`l2`.`iD`
WHERE `Library`.`iD` = 0x02
ORDER BY `Library`.`subsectionOrder`, `l2`.`subsectionOrder`, `l3`.`subsectionOrder`
This gets me a 3-level-deep hierarchy of data laid out as:
Layer 1 fields, Layer 2 fields, Layer 3 fields
- How to I make the query work for n levels of depth?
How do I make the results stack on top of each other rather than adding fields to the right?
Layer 1 Row Layer 2 Row Layer 2 Row Layer 3 Row Layer 3 Row Layer 2 Row Layer 3 Row Layer 2 Row