SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple Self Join ?

    using mysql5
    table A
    user smallint(3)
    userA smallint(3)
    userB smallint(3)

    table b
    employeeid smallint(3)
    employeename varchar(20)

    tableb data
    1 John Doe
    2 Jane Doe
    3 Clark Kent
    4 Mary Jane

    tablea Data
    1 2 4
    2 3 1
    3 1 4

    Want to do a select on table A which will display the records as
    John Doe Jane Doe Mary Jane
    Jane Doe Clark Kent John Doe
    Clark Kent John Doe Marj Jane

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,276
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Code:
    select u.employeename   as u_name
         , uA.employeename  as uA_name
         , uB.employeename  as uB_name  
      from tableA
    inner 
      join tableB as u
        on u.employeeid = tableA.user           
    inner 
      join tableB as uA
        on uA.employeeid = tableA.userA    
    inner 
      join tableB as uB
        on uB.employeeid = tableA.userB
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    to state it simply my friend u R O C K
    thanks a million and even thats inadequate


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
  •