|
-
October 15th, 2001, 10:32 PM
#1
SQL
Hi
I have a database table with two columns, Nname,NParent. Data are like;
Nname ,NParent
n1 ,origin
n2 ,n1
n3 ,n2
n4 ,n2
So what I want is a SQL statement , given a particular Nname( say n2) you should return all Nnames which has n2 as the parent; i.e n2,n3,n4.
I think this is something to do with a co-related subquerry. Please give me this urgent help.
thanks
-
October 15th, 2001, 10:58 PM
#2
Re: SQL
Hi
Sorry about this correction.
Actually the querry should give every level after the first level I mentioned in the original posted question. i.e also it should look for Nname's that have n3,n4 as their parent and so on..
thanks
-
October 16th, 2001, 02:27 AM
#3
Re: SQL
Try this :
SELECT lpad(' ',2 * (LEVEL - 1)) || Nname
FROM table_name
START WITH Nname = 'n1'
CONNECT BY PRIOR Nname = NParent
O/P:
n1
n2
n3
n4
Regards,
The Beret.
-
October 16th, 2001, 08:33 AM
#4
Re: SQL
>>SQL statement , given a particular Nname( say n2) you should return all Nnames which has n2 as the parent
select nname, nparent from yourtable where nparent = 'n2'
Iouri Boutchkine
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|