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 > DB2 > Query Help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-08-04, 10:56
rprp rprp is offline
Registered User
 
Join Date: Oct 2004
Location: Toronto
Posts: 3
Query Help

Hi

I'm trying to get a query working.

My db structure is

Schedule
id | home | away | home_score | away_score

where 'home' and 'away' reference primary keys in the Team table

Team
id | name | city

What I would like to do, is for each game in Schedule, select the actual name's of the teams playing (instead of just there ids)
I can't figure out the JOIN involved in this.

Any help would be appretiated, thanks

Last edited by rprp; 11-08-04 at 10:59.
Reply With Quote
  #2 (permalink)  
Old 11-08-04, 12:24
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
select t1.name as "home team", t2.name as "away team", s.home_score, s.away_score
from schedule s, team t1, team t2
where s.home=t1.id and s.away=t2.id;
Reply With Quote
  #3 (permalink)  
Old 11-08-04, 12:30
rprp rprp is offline
Registered User
 
Join Date: Oct 2004
Location: Toronto
Posts: 3
Thank you very much!

I had something similiar, but rather than "Team t1, Team t2" I was only selecting Team once. Argh, should have realized that.

Thanks again.
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