create cursor tree ( nodeno i, parentnodeno i ) insert into tree values ( 1, 0 ) insert into tree values ( 2, 0 ) insert into tree values ( 3, 0 ) insert into tree values ( 4, 1 ) insert into tree values ( 5, 1 ) insert into tree values ( 6, 1 ) insert into tree values ( 7, 2 ) insert into tree values ( 8, 7 ) insert into tree values ( 9, 8 ) select * ; from tree ; where tree.parentnodeno in ( select nodeno from tree where parentnodeno = 0 )the inner select finds all of the root nodes you are interested in and the outer select pulls their child nodes. So the result is 4,5,6,7. Nodes 8 and 9 are not picked because they are 2 and 3 levels respectively away from the root nodes.