SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: parent child relationship

  1. #1
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    parent child relationship

    TABLE

    CHILD PARENT NAME
    1 2 V1
    2 0 V2
    3 1 V3
    4 2 V4
    5 0 V5


    I want to print CHILDNAME and its PARENTNAME . What would be the query ?

  2. #2
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,462
    Mentioned
    35 Post(s)
    Tagged
    1 Thread(s)
    Code:
    SELECT child.name AS child_name
         , parent.name AS parent_name
      FROM daTable AS child
    LEFT OUTER
      JOIN daTable AS parent
        ON parent.child = child.parent
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •