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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

recursive select 2

Status
Not open for further replies.

Thorsten3

Programmer
Jan 28, 2001
22
JP
I'd like to represent a hierarchy in a table like

id name parent1 aaa null
2 bbb 1
3 ccc 1
4 ddd 3
is it possible to select reucursivly?
For example for id 4 I would like a result like this:
aaa-ccc-ddd
For id 3 like this:
aaa-ccc
 
not in ansi sql, as far as i know -- maybe some recent version of standard sql has introduced recursion, but that matters little if no actual databases out in the real world support it

oracle is an exception, you can do it in oracle using START WITH and CONNECT BY syntax


rudy
 
thanks rudy!

I'm using db2 at the moment. I suppose db2 can not do it!?

I will use oracle however in the near future, how would the select command actually look like for the example above?

thorsten
 
A hierarchical query in Oracle would look something like

select * from your_table
start with id = {identify top level row(s) here}
connect by prior id = parent1;
 
browsing through the forum I saw that you may indeed use recursive select with DB2: thread220-479915

Haven't tried it myself, but I will sure do soon.
 
There is recursion in DB2, just look for WITH.

Dieter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top