- Uninteresting
- Misleading
- Offensive
- Repetitive
- Other
SUB-TREE WITHIN A TREE in MySQLIn my MYSQL Query to Create Table:
I have inserted a set of tuples (Query):
The inserted rows has following Tree-Hierarchical-Relationship:
I written a query to find relationship:
And output is:
[QUESTION] Instead of complete Hierarchical Tree, I need a
Please help me on this. If not query, a stored-procedure can be helpful. I tried, but all efforts were useless! |
|||||||||||||||||||||
migrated from *.com Dec 8 '12 at 9:42This question came from our site for professional and enthusiast programmers. |
|||||||||||||||||||||
|
I already addressed something of this nature using Stored Procedures : Find highest level of a hierarchical field: with vs without CTEs (Oct 24, 2011) If you look in my post, you could use the GetAncestry and GetFamilyTree functions as a model for traversing the tree from any given point. UPDATE 2012-12-11 12:11 EDTI looked back at my code from my post. I wrote up the Stored Function for you:
It actually works. Here is a sample:
There is only one catch. I added one extra row for the owner
Here is the data
|
|||||||||
|
- Uninteresting
- Misleading
- Offensive
- Repetitive
- Other
What you are using is called Adjacency List Model. It has a lot of limitations. You'll be problem when you want to delete/insert a node at a specific place. Its better you use Nested Set Model. There is a detailed explanation. Unfortunately the article on mysql.com is does not exist any more. |
|||||||||
|
protected by RolandoMySQLDBA Dec 11 '12 at 18:38
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?