使用另一个表从一行加入两个ID

时间:2017-05-19 09:38:17

标签: mysql

我有两张桌子......

夹具

enter image description here

团队

enter image description here

现在我想展示两队(lteam和vteam)的名字 彼此在一张桌子里。我曾尝试 LEFT JOIN 这些表,但这不起作用。猜猜你知道为什么吗?

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'

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

联接不正确。改变这个:

LEFT JOIN teams as a ON fixtures.lteam = teams.id
LEFT JOIN teams as b ON fixtures.vteam = teams.id
                                            |

对此:

LEFT JOIN teams as a ON fixtures.lteam = a.id
LEFT JOIN teams as b ON fixtures.vteam = b.id
                                         |

您还需要在连接中使用别名