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 > Data Access, Manipulation & Batch Languages > ANSI SQL > Double join... kind of...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-23-04, 02:21
Zcumbag Zcumbag is offline
Registered User
 
Join Date: Apr 2004
Posts: 31
Double join... kind of...

I'm having problem getting the output i want.

I have a table looking like this (tbl_team)

team_id | team_name
1 | TEAM1
2 | TEAM2
3 | TEAM3
...

and another one like this (tbl_match)

match_id | home_team | away_team | score
1 | 1 | 3 | 3-1
2 | 2 | 3 | 0-0
3 | 2 | 1 | 1-5
...

I am trying to form a question looking like this:

home team | away team | score
TEAM1 | TEAM3 | 3-1
TEAM2 | TEAM3 | 0-0
TEAM2 | TEAM1 | 1-5
...

can anyone help me with this? It's easy to make this output in my programming enviroment (VS.NET) but I would really like for a sql-statement to have this output.

Thanks!
Reply With Quote
  #2 (permalink)  
Old 10-23-04, 04:30
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
select h.team_name as hometeam
     , a.team_name as awayteam
     , score
  from tbl_match
inner
  join tbl_team as h
    on home_team = h.team_id  
inner
  join tbl_team as a
    on away_team = a.team_id
__________________
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