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

Home -> Community -> Usenet -> c.d.o.misc -> Re: Tree walk using a single SQL query?

Re: Tree walk using a single SQL query?

From: Ryan Gaffuri <rgaffuri_at_cox.net>
Date: 10 Dec 2003 05:17:30 -0800
Message-ID: <1efdad5b.0312100517.1d335980@posting.google.com>


cutelittleyoungseeker_at_yahoo.com (Young Seeker) wrote in message news:<840b9a17.0312091500.4565c1f2_at_posting.google.com>...
> Hi,
>
> I would like to know if it is possible to do a tree walk where the
> connectivitiy information is stored in a database table.
>
> 1) I have a table that has colums like
>
> Node_Id Parent_Id Description
>
> What I would like to do is given a Node_Id, list all the rows whose
> Node_Id's are descendents of the Node_Id.
>
> Is this possible using a single sql query? (I know I can do it in a
> program, PL/SQL or otherwise.)
>
> 2) If the above is not possible, will adding another column called
> Position help? The Position column orders the children of the given
> parent.
>
> 3) If that is also not possible what if the data in the table is
>
> Node_Id Parent_Id Next_Sibling_Id
>
> The Next_Sibling_Id is the next sibling or null if there is no more.
>
>
> You may assume that the data in the table is all consistent and the
> data represents a tree (or a forest) i.e. it doesn't have loops and
> every node other than a root node has a parent and things like that.
>
> And also, the query can be a complex one with sub-queries, joins and
> unions - just that it has to be one SQL statement.
>
> P.S. One more thing, the depth of the tree is not fixed and I do not
> know what it is.
>
> Thanks,
> Young Seeker

if your going to post a homework assignment the least you can do is re-word it and not just copy and paste it.

L is for loser. Received on Wed Dec 10 2003 - 07:17:30 CST

Original text of this message

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