PostgreSQL - 列引用'LibraryID'含糊不清

时间:2015-11-17 00:45:31

标签: sql postgresql

我有以下表格:

A(StudentID, Name, Years)
B(Age, LibraryID)
C(Years, Grade, LibraryID)

这是我的代码中给我带来麻烦的一部分:

c1 cursor for select LibraryID, Age, Grade, Name from A,B,C where  b.LibraryID = c.LibraryID and c.Years=a.Years;

我收到以下错误:

column reference "LibraryID" is ambiguous

1 个答案:

答案 0 :(得分:2)

确实有一个含糊不清的名字。您的查询中有两个LibraryID字段:一个来自表B,另一个来自表C。您只需指定要选择字段的表格,例如:

c1 cursor for select B.LibraryID, Age, Grade, Name 
from A,B,C where  B.LibraryID = C.LibraryID and C.Years=A.Years;

您在LibraryID子句中的from字段上加入这些表的事实并不能使它们与select子句相等