how to retrieve a child node's immediate parent node from a tree table?
Hello
Hi,
I have a category_subcategories table, and I would like to know how to construct a sql and sub-sql for retrieving a child node's immediate parent node.
Here is my first part of the sql, it only returns the node "Flash"'s parent and its grand-parents:
SELECT parent.category_name, node.lft, node.rgt
FROM category_subcategories AS node,
category_subcategories AS parent
WHERE node.lft > parent.lft AND node.lft < parent.rgt
AND node.category_name = 'FLASH'
ORDER BY parent.lft;
----------------------
| name |
----------------------
| ELECTRONICS |
| PORTABLE ELECTRONICS |
| MP3 PLAYERS | |
----------------------
how can I modify this query so that it returns Flash' parent - 'MP3 Players'?
Thanks a lot
Sam