我有两张如下表:
表1 :
teamid teamname
1 AAA
2 BBB
3 CCC
表2 :
id team1 team2
1 1 2
2 2 3
3 1 3
表2包含两个字段 team1 和 team2 ,引用table1 teamid 。
预期结果:
id team1 team2
1 AAA BBB
2 BBB CCC
3 AAA CCC
答案 0 :(得分:1)
您需要加入table1
2次
select
t2.id,
t1.teamname as team1,
t11.teamname as team2
from table2 t2
join table1 t1 on t1.teamid = t2.team1
join table1 t11 on t11.teamid = t2.team2