简体   繁体   English

将一行中的两个ID与另一张表连接起来

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM