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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Start with-connect by SQL for lowest level in hierarchy or tree structure

user10648285Oct 18 2011 — edited Oct 18 2011
Hi,

In a tree structure as given below how can i get all the lowest level (of tree) child records like - E, H, G and D.
A has B, C, D at level 2
B has E and F at level 3, and C has G at level 3
F has H at level 4

A
|l |l |l
B C D
|l |l |l
E F G
|l
H

I was able to use start with and coonect by to give all the levels of the tree as follows -
SELECT task_id,parent_task_id, top_task_id,level
FROM pa_tasks
WHERE project_id = :p
START WITH parent_task_id IS NULL
CONNECT BY PRIOR task_id = parent_task_id

Thanks

Edited by: user10648285 on Oct 17, 2011 11:42 PM

Edited by: user10648285 on Oct 17, 2011 11:42 PM

Edited by: user10648285 on Oct 17, 2011 11:42 PM

Edited by: user10648285 on Oct 17, 2011 11:43 PM
This post has been answered by Kim Berg Hansen on Oct 18 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 15 2011
Added on Oct 18 2011
4 comments
2,161 views