richard grantham
richard grantham

Reputation: 21

inner join selecting multiple id as name

I am really stuck, i have 2 tables with football match data:

team

id, name

fixture

id, hometeam, awayteam

I have done the following:

SELECT hometeam, awayteam, score, week FROM fixture
join team on fixture.hometeam = team.id;

basically the hometeam and awayteam are id numbers that relate to the team table, but i need to output these as the actual text name.

any help would be grately appreciated

thanks :)

Upvotes: 2

Views: 1258

Answers (1)

Quassnoi
Quassnoi

Reputation: 425321

SELECT  th.name AS hometeam_name, ta.name AS awayteam_name, week, score
FROM    fixture
JOIN    team th
ON      th.id = fixture.hometeam
JOIN    team ta
ON      ta.id = fixture.awayteam

Upvotes: 2

Related Questions