加入MySql Workbench中的团队

时间:2016-01-24 14:24:56

标签: mysql sql join mysql-workbench

我有两张桌子:我想展示彼此对战的球队及其得分。

enter image description here

我试过了:

SELECT Wedstrijd.Team1, Wedstrijd.Team2, Wedstrijd.ScoreTeam1, Wedstrijd.ScoreTeam2
FROM Wedstrijd
JOIN Team ON idTeam = idWedstrijd

结果:

'1', '2', '1', '4'
'3', '4', '3', '1'

现在我需要ID附带的名字。

  • Naam =姓名
  • Stad = City

1 个答案:

答案 0 :(得分:2)

SELECT 
    W.Team1, t1.Naam, t1.Stad,  
    W.Team2, t2.Naam, t2.Stad, 
    W.ScoreTeam1, w.ScoreTeam2
FROM Wedstrijd AS W
JOIN Team AS t1 ON t1.idTeam = w.Team1
JOIN Team AS t2 ON t2.idTeam = w.Team2