SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    301
    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 gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 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
    rudy.ca | @rudydotca
    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
  •