C#,vb.net,MVC,Jquery,javascript,jscript,vbscript,html,vb,sharepoint,COM,WPF,WCF,Wwf,Asp,Asp.net,questions & answers,

Latest in Sports

Wednesday, October 10, 2012

write query to fetch the hierarchy based on child node (leaf node),

Hi,
I need to write query to fetch the hierarchy based on child node (leaf node), I am able to fetch the same using parent node (top level node).
Below is the query to fetch the hierarchy by parent id (here 107 is parent id)
SELECT   node_id,
            node_name,
            parent_id,
            node_depth
            FROM   temp_node_details nd
     START WITH   nd.node_id = 107 
CONNECT BY   PRIOR node_id = parent_id
But I need to get same hierarchy based on chile node (last leaf node, ie: 109)
Please help me write this query, thanks for you’re help in advance.
Query’s to create sample tables and its data.
create table temp_node_details (node_id  integer, node_name varchar2(300), parent_id integer, node_depth integer) ;
insert into temp_node_details values(107, 'DDD', 0 , 0);
insert into temp_node_details values(108, 'DDD1', 107 , 1);
insert into temp_node_details values(109, 'DDD2', 108 , 2);
I am using Oracle DB.
Thanks & Regards
Basagalla,

No comments:

Post a Comment