2012-10-21 58 views
0

目前我有類似下面SQL雙重加入排序依據

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 

一個表,我不希望球隊的名字是比賽,即我想表1的精確複製雖然與隊名像下面

Table3 
    hTeam-------------aTeam-- 

    Teamname3-------TeamName5 

    TeamName4 ----- Teamname7 

    TeamName2 ----- TeamName8 

希望我解釋得很好。

+0

什麼是你的結果由原始結果集(肚裏3 - 4 - 2)命令? –

回答

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 
+0

在[sqlfiddle](http://sqlfiddle.com/#!2/a3d35/1/0)上查看。 – eggyal

+0

我相信他想阻止查詢重新排序的結果。 –