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: Newbie: sql query

Re: Newbie: sql query

From: Michel Cadot <micadot{at}altern{dot}org>
Date: Wed, 28 Jun 2006 18:01:12 +0200
Message-ID: <44a2a7c8$0$11897$636a55ce@news.free.fr>

<gfiuni2_at_gmail.com> a écrit dans le message de news: 1151499043.225637.213670_at_p79g2000cwp.googlegroups.com...
|
| Hello,
|
| Given the table below:
|
| id | parent_id
| -------------------------
| 1 | NULL
| 7 | 1
| 9 | 7
| 13 | 9
| 16 | 13
| .....
|
|
| I want to get the id of the fisrt register (id=1) given any other id
| (7, 9 ,13, ..). It is posible to do it with a SQL query or do I need to
| use PL/SQL?
|
| Thanks in advance,
| Jose Luis.
|

select id, connect_by_root id input_id
from t
where connect_by_isleaf = 1
connect by prior parent_id = id
start with id = &input_id
/

Regards
Michel Cadot Received on Wed Jun 28 2006 - 11:01:12 CDT

Original text of this message

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