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 > MySQL Join Help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-24-10, 19:33
seanmt seanmt is offline
Registered User
 
Join Date: May 2010
Posts: 2
MySQL Join Help

I am wanting to get data from one table using information from one. How would I go about doing this?

The ftv_match table has a home team and an away team id which relate to the ftv_team table. So what I want to be able to do is get the team names for both of them from the ftv_team table. The code I have at the moment only gets the name for the home team. What do I need to change to get the name for the away team too?

Code:
SELECT * FROM ftv_match
JOIN ftv_team
ON ftv_match.home = ftv_team.id
Example row from ftv_match
Code:
id	home	away	competition	date		time	channel
5545	243	433	12		2010-07-03	124500	2
Example row from ftv_team
Code:
id	name
243	Team X
433	Team Y
Reply With Quote
  #2 (permalink)  
Old 05-24-10, 19:54
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
SELECT m.id
     , m.competition 
     , m.date  
     , m.time 
     , m.channel
     , h.name AS home_team_name
     , a.name AS away_team_name
  FROM ftv_match AS m
INNER
  JOIN ftv_team AS h
    ON h.id = m.home
INNER
  JOIN ftv_team AS a
    ON a.id = m.away
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 05-25-10, 07:03
seanmt seanmt is offline
Registered User
 
Join Date: May 2010
Posts: 2
Brilliant, thanks for the quick response as well!
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