[英]Join two ids from one row with another table
I got two tables... 我有两张桌子...
fixtures 固定装置
and teams 和团队
Now I would like to display the names of both teams (lteam and vteam) playing against each other in a table. 现在,我想在表格中显示两个互相对战的球队(lteam和vteam)的名称。 I have tried to LEFT JOIN those tables, but that does not work.
我试图左联接那些表,但这不起作用。 Guess you know why?
猜猜你知道为什么吗?
SELECT * FROM fixtures
LEFT JOIN teams as a ON fixtures.lteam = teams.id
LEFT JOIN teams as b ON fixtures.vteam = teams.id
WHERE date_ko = '2017-05-19'
Thanks for your help! 谢谢你的帮助!
The joins are not correct. 联接不正确。 Change this:
更改此:
LEFT JOIN teams as a ON fixtures.lteam = teams.id
LEFT JOIN teams as b ON fixtures.vteam = teams.id
|
To this: 对此:
LEFT JOIN teams as a ON fixtures.lteam = a.id
LEFT JOIN teams as b ON fixtures.vteam = b.id
|
You need to use the alias in the join too 您也需要在连接中使用别名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.