Mysql recursion?

It is possible, but you need to change your database structure; once the changes are made, you can retrieve a tree of any depth in one query. The queries are slightly more complex, but it's still pretty straightforward.

  • Storing Hierarchical Data in a Database (SitePoint) - this article is step by step, very clear.
  • Managing Hierarchical Data in MySQL - not as clear as the above.

With the table structure you have shown, this cannot be done with MySQL as it does not support recursive queries