If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > query JOIN question (2 JOINs ?)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-04-04, 04:45
elRey elRey is offline
Registered User
 
Join Date: Apr 2004
Posts: 4
query JOIN question (2 JOINs ?)

table prizes (l_playerid, s_playerid, l_prize, s_prize)
1 - 1 - 500 - 350
2 - 1 - 650 - 245
1 - 2 - 500 - 65
2 - 2 - 150 - 85
3 - 3 - 95 - 125
5 - 2 - 350 - 205

table players (playerid, name)
1 - Bob
2 - Jay
3 - Suzie
4 - David
5 - Rick
6 - Jane

WHERE prizes.l_playerid = players.playerid OR prizes.s_playerid = players.playerid


HOW can I return this:

result (l_player_name, s_player_name)
Bob - Bob
Jay - Bob
Bob - Jay
Jay - Jay
Suzie - Suzie
Rick - Jay


With one query???

Thanks,
Rey
Reply With Quote
  #2 (permalink)  
Old 04-04-04, 09:34
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
PHP Code:
select lp.name as l_player_name
     
sp.name as s_player_name
     
l_prize
     
s_prize
  from prizes
inner       
  join players 
as lp
    on prizes
.l_playerid lp.playerid
inner       
  join players 
as sp
    on prizes
.s_playerid sp.playerid 
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On