SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Help with JOIN

  1. #1
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with JOIN

    Hello

    I have a table with a few columns. Now, two columns are this :

    winner_id, loser_id

    Now what I want is all the DISTINCT players id no matter winner or loser.

    so that if the table has following data:

    winner_id, loser_id
    1,2
    2,3
    1,3
    4,1
    2,4
    4,3

    i want a list like:

    player_ids
    1
    2
    3
    4

    Please guide me how this can be achieved, thanks !

    ZH

  2. #2
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do a UNION on the table, once for winners, once for losers.

  3. #3
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, can you please give me an example query ?

  4. #4
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    700
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Code:
    select winner_id player_ids
      from t
     union
    select loser_id
      from t

  5. #5
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow thanks a lot, i got it.


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
  •