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!

Hierarchical query

341668Mar 28 2006 — edited Mar 29 2006
Hi,
I have 2 tables:

Select group_id from address_group;

group_id
--------
1
2
3
4
5

Select group_id,address_id,group_flag from address;

group_id address_id group_flag
-------- ---------- ----------
1 2 Y
1 3 Y
1 100 N
1 500 N
2 4 Y
2 200 N
2 300 N
3 100 N
3 7 N
3 400 N
4 500 N

The group_flag marks an address_id as being a group_id(parent address_id)

I need a select statement that will return all non-group address_ids(children,grandchildren,etc) for each group_id.

group_id address_id group_flag
-------- ---------- ----------
1 500 N
1 200 N
1 300 N
1 100 N
1 7 N
1 400 N
1 100 N
1 500 N
2 500 N
2 200 N
2 300 N
3 100 N
3 7 N
3 400 N
4 500 N

In fact I don't need last column(group_flag), I used it to show that the final result set contains only non-group address_ids.

Thank you,

Monica
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 26 2006
Added on Mar 28 2006
15 comments
709 views