2013-06-21 75 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

谢谢..