I have a table that describes a hierarchical relationship with no bounds on the size. A simple example would be:
|ParentID |Child ID|
|1 |2 |
|2 |3 |
|1 |4 |
|5 |6 |
I need a query that for a given parent, gives a flat list of every child, all the way down, so for 3
it would just return 4
, but for 1
it would return 2,3,4
.
I'm coming fresh to MySQL from many years of SQL Server so am still getting used to how its more advanced query features work. There are a few examples of this on SO but they only work on hierarchies with fixed bounds on depth. I'm on MySQL 5.7 so sadly don't have CTEs.