how to sql query this?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • steve

    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

  • NoName

    #2
    Re: how to sql query this?

    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 "Hierarchic al 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



    Comment

    Working...