I have a node tree in a MySQL Base and I want to get result like this
Node_1
Node_1_1
Node_1_1_1
Node_1_1_2
Node_1_2
Node_1_2_1
Node_2
Now I have a query that gives me only one deep child and all rests at the end of a list. ( Node_1_1_2 would be the last in this example )
Here is my code:
SELECT name,
if ( parentId = -1, "Root",
if ( exists( SELECT id FROM citizensTree AS t2 WHERE t1.id = t2.parentId), "Inner", "Leaf")
)
AS type FROM citizensTree as t1
I love this SQL solution:
SELECT t.id, t.name FROM tree t CONNECT BY prioir id = parentId START WITH parentId = -1
But it doesnt work in MySQL