Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: How to chain through tables.

Re: How to chain through tables.

From: <mgogala_at_rocketmail.com>
Date: Sun, 13 Dec 1998 06:35:20 GMT
Message-ID: <74vn78$6k1$1@nnrp1.dejanews.com>


In article <roy-1112982100410001_at_mcsv29-p20.med.nyu.edu>,   roy_at_popmail.med.nyu.edu (Roy Smith) wrote:
> I've got a table, call it foo, which looks sort of like this:
>
> id name parent
> 1 foo 2
> 2 bar 4
> 3 other 5
> 4 baz NULL
> 5 stuff NULL
> 6 xyz 2
>
> Each row in the table is essentially a node in a tree. I want to get all
> the rows which trace the chain from a given row, through the parent
> pointers, to the root, i.e. starting with 1, I want to get back rows 1, 2,
> and 4. Starting with 6, I want to get 6, 2, and 4. And so on. Is there
> a single SQL statement I can write to execute that query?
>

Try something like
select * from foo
connect by prior id=parent
start with id=6;

--
Mladen Gogala

-----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own Received on Sun Dec 13 1998 - 00:35:20 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US