Team
fields: id_team, name
和
Team_Match
fields: id_team1, id_team2, id
我需要的是在同一查询中调用"name"
和"id_team1"
的{{1}}的查询,这些ID是来自"id_team2"
表{{1}的外键}} field。
这是可能的,还是我需要查询每一个?
感谢您的回答。
答案 0 :(得分:0)
您可以在此处使用多个联接来获取此功能。对于team1,第一次加入可以在team_match
和team
之间,以获得team1的名称。然后你可以再次加入team2来获得team2的名字。请务必清楚地为您的表格添加别名:
SELECT t1.name AS team1Name, t2.name AS team2name
FROM team_match t
JOIN team t1 ON t1.team_id = t.team1_id
JOIN team t2 ON t2.team_id = t.team2_id;