I have the following columns in a table:

posts.id
posts.parentId REFERENCES posts.id

This represents a tree that has a single root node, and each node can
have 0 or more children. posts.id is the id number of a node, and
posts.parentId is the id number of that node's parent (is NULL for the
root node).

Is there a way to do "SELECT ... FROM posts ORDER BY <magic>" where
<magic> is something that will give me depth-first-traversal order?

The best solution I've been able to think of so far, short of reading
the entire tree into memory and sorting it with a procedural language
such as Perl, is to make a new column called "posts.order" and do
"ORDER BY posts.order", and have some code that maintains posts.order
whenever a new node is inserted into the tree. I was hoping there's a
way MySQL could automatically keep track of depth-first-traversal
order for me, though...

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to