mysql:在同一个表中检索多个链接字段

时间:2010-06-28 20:42:10

标签: mysql

小组: id_team 名称

匹配 id_match id_team_1 id_team_2 score_1 score_2

我想通过显示球队名称来显示比赛得分。例如:

巴西3 - 智利0

这是我到目前为止所尝试的: SELECT * FROM匹配INNER JOIN团队ON match.id_team_1 = team.id_team AND match.id_team_2 = match.id_team

当然没有用。有什么想法吗?

1 个答案:

答案 0 :(得分:4)

SELECT a.name, m.score_1, b.name, m.score_2
FROM matches AS m
INNER JOIN teams AS a
  ON m.id_team_1 = a.id_team
INNER JOIN teams AS b
  ON m.id_team_2 = b.id_team