简体   繁体   English

将一个表的两列连接到另一表的一列

[英]Join two columns from one table to one column from another

I am trying to use my home_team and away_team fixture_id's to get their name values from a different table. 我正在尝试使用我的home_team和away_team Fixture_id从不同的表中获取它们的名称值。

This works to get the name value of home_team 这可以获取home_team的名称值

SELECT * FROM fixtures JOIN teams ON fixtures.home_teamID = teams.TeamID

To get the name value of the away team I have the following 为了获得客队的名字,我有以下几点

SELECT * FROM fixtures JOIN teams ON fixtures.home_teamID = teams.TeamID 
JOIN teams ON fixtures.away_teamID = teams.TeamID

But this then returns a boolean 但这然后返回一个布尔值

you should join the teams table two time using two different alias 您应该使用两个不同的别名两次加入teams表

  SELECT fixtures.* a.* , b.*
  FROM fixtures 
  JOIN teams a ON fixtures.home_teamID = a.TeamID
  JOIN teams b ON fixtures.home_teamID = b.TeamID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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