我有两个表,一个名为Teams,另一个名为Scores
public MyRepository(CustomContext context)
{
_context = context;
}
id - team_name
1 - Reds
2 - Blues
3 - Greens
4 - Yellows
我希望通过比较主队和客队的ID并从队伍中返回队名来获取我的php文件中返回的队名。
我已经使用过:
home_team_id - away_team_id
1 - 2
3 - 4
以及带来类似值的LEFT JOIN,但这些只返回重复项。
是否有人能够提供协助,以便根据团队中的team_name反映出主队和客队的身份证明。
答案 0 :(得分:2)
您需要与团队一起为home_team加入乐谱,并加入另一次for away_team:
select b.team_name home, c.team_name away
from scores a
join teams b on a.home_team_id = b.id
join teams c on a.away_team_id = c.id