目前我有一张如下表
Table1
hTeam-----aTeam-------date---
3----------5 ------2012/01/01
4 -------- 7 ------2012/01/04
2 -------- 8 ------2012/01/05
我使用双内连接来获取id1和id2的值,代码如下:
Select hTeam As col1,
aTeam As col2
From fixtures as t
Join team as d1 On ( d1.teamid = t.col1)
Join team as d2 On ( d2.team = t.col2 )
这会创建一个像这样的表
Table2
hTeam-------------aTeam--
Teamname1-------TeamName1
TeamName2 ----- Teamname2
TeamName3 ----- TeamName4
我不希望团队名称是匹配,即我想要完全复制table1,尽管团队名称如下所示
Table3
hTeam-------------aTeam--
Teamname3-------TeamName5
TeamName4 ----- Teamname7
TeamName2 ----- TeamName8
希望我能够很好地解释这一点。
答案 0 :(得分:0)
不完全确定问题是什么,因为你似乎已经拥有它了:
SELECT h.name AS home, a.name AS away
FROM fixtures AS f
JOIN team AS h ON h.teamid = f.hTeam
JOIN team AS a ON a.teamid = f.aTeam