I have a tree-like data model stored in a MYSQL database. The tree is traversed by using two fields on each 'node' object:
- id
- parent_id
The root id has a parent_id of 'null' and all other nodes in the tree reference a parent id.
If I want to get a list of all node ids in this tree, I have to recursively traverse the tree and collect one or more attributes of each node, using what is essentially a for loop with many queries.
I was wondering if there was a way to do this all more efficiently with on query in SQL