内部联接选择多个id作为名称

时间:2011-01-28 15:50:41

标签: mysql select join

我真的被困了,我有2张足球比赛数据表:

id, name

夹具

id, hometeam, awayteam

我做了以下事情:

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

基本上,hometeam和awayteam是与团队表相关的id号,但是我需要输出这些作为实际的文本名。

任何帮助都会受到赞赏

谢谢:)

1 个答案:

答案 0 :(得分:2)

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