Finding all parents in mysql table with single query (Recursive Query)
I have this schema
I have this schema
I have to build a tree that will contain about 300 nodes inside it. The tree has no depth limitations. So it can have 3 or 15 levels. Each node can have an unlimited number of children.
I have just made the update/add/delete part for the “Closure table” way of organizing query hierarchical data that are shown on page 70 in this slideshare: http://www.slideshare.net/billkarwin/sql-antipatterns-strike-back
I am trying to build an un-oredered list menu tree from my database in PHP and MySQL.
I’ve been trying to figure this out but I haven’t gotten anywhere.Hopefully someone can come to my rescue.
I have a set of data that’s organized hierarchically that should be able to grow to an arbitrary size. I need to retrieve the entire tree, but I can’t figure out how to do it with just SQL. My current solution is to create a temporary table and use a recursive function to successively query branches of the tree and then store the result in the temporary table which I subsequently query again to produce my desired result.
What is the best way to sort a table like this:
I’d need a MySQL query that moves a node and all its children within a nested set. I found this site, but that function just seems so illogical – there’s no universeid
or treeid
in a nested set model, and the code itself is just longer than what feels required. The only extra column I’ve got in the table is parent
.
I am not totally sure I am naming this right, but please bear with me.
Below is what I have in my table.