Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is is possible to solve this Issue using SQL

Status
Not open for further replies.

traj

MIS
Jan 16, 2002
1
AU
Hi All,

Here is the description of the problem :

Child Parent
16 9
17 9
18 16
19 17


Now the deal is I'll get on parent key from which I need to pull out all its children and obviously I do not know many children one parent can have. Can somebody tell me a best way to get all the children of a given parent id. Also suggest me if it is doable using a dynamic query.

From the above sample it goes like this :
9 -> 16 -> 18
17 -> 19 ...
I need the output as
9
16
17
18
19
...

Thanks

Draj
 
Hi there,

I've never actually used them, but you might want to look into "heirarchical queries". I believe they do exactly what you want, and may be the only way to "traverse" a tree of data in SQL.

I've seen heirarchical queries referenced in Oracle docs - I'm not sure about any other RDBMS.

Here's an interesting article I just found, but it deals mostly with stored procedures and functions:


HTH,

sacha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top