mysql - create treeview looping query -
i have designed treeview structure below: *parentid = 0 means tree root
id parentid 1 0 2 0 3 1 4 1 5 1 6 3 7 4 8 5 9 5 10 5 11 2 12 2 13 10
when pass parameter of "1" return result of under root "1", expected result:
id parentid 1 0 3 1 4 1 5 1 6 3 7 4 8 5 9 5 10 5 13 10
possible solve single query?
in way stored tree now, not possible entire tree in 1 pure sql query. need write loop in other language (c#, stored procedure supports loops, ...) fetch tree.
this nice article describing how work way of storing tree (including fetching tree , removing items tree).
even more interesting, article describes way store trees in database table does allow fetching entire tree in single query. it's called pre-order tree traversal. can more information. i've found c# implementation. involves more logic way using now, more performant smallest trees.
Comments
Post a Comment