CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: SQL

  1. #1
    Join Date
    Jan 2001
    Posts
    18

    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




  2. #2
    Join Date
    Jan 2001
    Posts
    18

    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


  3. #3
    Join Date
    Jul 2001
    Location
    Mumbai,India
    Posts
    382

    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.


  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    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]
    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
  •  





Click Here to Expand Forum to Full Width

Featured