문제

I have a db structure as in the image attached, where in column A I have fathers and in column B sons. As you see a son can also be a father. Now, I would like to know if there is a way through a single query mysql to select all the infinite hierarchical tree.

Thank you.

Father/Sons db structure

도움이 되었습니까?

해결책

There is not a known way of doing this in MySQL with infinite levels. You could always use n self-joins, but using PHP is probably a better approach.

You can however restructure your db schema, for example using Pre Order Tree Traversal:

Storing Hierarchical Data in a Database

This will increase the complexity and runtime of inserting data, but will make it much easier to fetch a tree or subtree.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top