2013-06-21 77 views
0

我有2種表貨幣和對有以下字段,的Sybase查詢多個外鍵指向一個主鍵

貨幣

  • Currencies_ShortName

  • Currencies_Id(主鍵)

成對

  • Pairs_ShortName

  • Currencies_Id_1參考(貨幣)Currencies_Id

  • Currencies_Id_2參考(貨幣)Currencies_Id

我想顯示Pairs_ShortName,Currencies_Id_1 & Currencie帶有Currencies_ShortName的s_Id_2。

我試圖
Select a.Pairs_ShortName, a.Currencies_Id_1, a.Currencies_Id_2, b.Currencies_ShortName from Pairs a, Currencies b where a.Currencies_Id_1 = .Currencies_Id

但它只顯示Pairs_ShortName,Currencies_Id_1,Currencies_ShortName。

我想顯示Pairs_ShortName,Currencies_Id_1,Currencies_ShortName,Currencies_Id_2,Currencies_ShortName

+1

爲什麼您的Pairs表中有兩個貨幣ID外鍵?你想在這裏做什麼?你的Pairs桌子上有主鍵嗎?您在where子句中缺少'b'前綴,即b.Currencies_Id。 – Alicia

回答

0

檢查下面的查詢,

選擇
p.Pairs_ShortName,p.Currencies_Id_1,c1.Currencies_ShortName1,p.Currencies_Id_2,C。 Currencies_ShortName2
從 成對p,貨幣C1,C2的貨幣
其中p.Currencies_Id_1 = c1.Currencies_Id
和p.Currencies_Id_2 = c2.Currencies _Id

謝謝..