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 for basketball game

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-08-04, 07:06
Oddish Oddish is offline
Registered User
 
Join Date: Mar 2003
Posts: 43
Query for basketball game

I've got a table containing basketball games and a table containing teams (se picture). I would like some help with a query that will select all the information from the games table and also get the names of the teams playing. The teams are as you can see referensed by "hometeam" and "awayteam" in "games". Is this even possible?
Attached Images
File Type: gif tables.gif (4.5 KB, 76 views)

Last edited by Oddish; 01-08-04 at 07:08.
Reply With Quote
  #2 (permalink)  
Old 01-08-04, 07:37
Oddish Oddish is offline
Registered User
 
Join Date: Mar 2003
Posts: 43
Wow, I'm better at this than I thougt! It suddenly just came to me! I would however appreciate some feedback on this SQL. Is is an ok query or can it be optimized in some way?
Code:
SELECT g.*, t1.name AS hometeam, t2.name AS awayteam
FROM (games AS g INNER JOIN teams AS t1 ON g.hometeam = t1.teamid)
INNER JOIN teams AS t2 ON g.awayteam = t2.teamid
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