470,618 Members | 1,727 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,618 developers. It's quick & easy.

how to sql query this?

Hi,

I have a table that contains data keys similar the following, where each
letter is a key to an address

a,b
a,c
c,b
b,d
d,f
x,y
p,q

if i pass in a key such as "a" how can i return the items that are connected
to "a" both directly & indirectly?

I.E
a,b
a,c
c,b ( via a,c)
b,d (via a,b)
d,f ( via a,b+b,d)

the parent key is always in col1, the child in col2

steve

Jul 19 '05 #1
1 2172
> I have a table that contains data keys similar the following, where each
letter is a key to an address [...snipped...] if i pass in a key such as "a" how can i return the items that are connected to "a" both directly & indirectly? [...snipped...] the parent key is always in col1, the child in col2

Hello,
have a look at "Hierarchical query" chapter in your Oracle manual.

your problem can be solved with a select like this one:

SELECT * from MyTable
CONNECT BY PRIOR col2=col1
START WITH col1='a';

This return all items in a "tree", starting from the one whose parent has
"a" value.

Regards

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by joemyre | last post: by
16 posts views Thread by cover | last post: by
3 posts views Thread by Nick Truscott | last post: by
3 posts views Thread by Tom Mitchell | last post: by
1 post views Thread by Nicolae Fieraru | last post: by
5 posts views Thread by Ryan Hubbard | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.