开发者

Get tree of single item in MySQL hierachircal database

I want to retrieve the path to a single node in a hierachical database where only the parent node ID is stored as a reference. Could someone give me a query or some advice on how to write a query (ideally the first option - I'm a MySQL noob) so that all the node titles in the end node's path are given in a generated table?

id   name          depth
10   Top level     0
22   Second level  1
34   3rd level     2
43   End node      3

I want to use this data to create on of those "you are here" lists like开发者_开发技巧:

Home > Forums > Stuffs > ... > Topics

Thanks for any help,

James


This is only possible for a fixed number of levels, as there is no recursion in SQL.

You can convert your data structure from the "adjacency list" model you have to the so-called "nested sets" model. With that model a "find the path to the top" query is possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜