There is a table of the form id, name, parent_name. How to build a tree on it, or at least sort by top-down hierarchy? Thank you in advance!
- You would clarify what you want, in what programming language, for example. Just if, for example, to speak in the most general form, then topological sorting is applicable. - Harry
- The question is strange. Create the root element root with name = parent_name. Then to it add child'ov at child parent_name = name of its ancestor. - koks_rs
- @Harry algorithm can be implemented in any language - Sergey Tambovtsy
- @koks_rs at this level I myself imagine how it should be, but I can’t think of an algorithm - Sergey Tambovtsy
- oneEntity Framework is of course a cool thing. But what about recursive queries? And the option in my first comment makes it easy. Yes, there is even nothing to do. They took the root, and the rest will stretch itself. Normally, for communication, use id and parent_id, the Model Editor will detect the connection itself. There will be an entity with a parent field and a children list field. Here is your tree - Sergey
|
1 answer
Hierarchy in SQL can be organized by a variety of methods. One of the simple ones is to add a path field http://www.onlamp.com/pub/a/onlamp/2004/08/05/hierarchical_sql.html
|