Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to retrieve a child node's immediate parent node from a tree table?

samsam8899Mar 20 2011 — edited Mar 20 2011
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 17 2011
Added on Mar 20 2011
5 comments
811 views