[英]#1052 - Column 'syear' in where clause is ambiguous
When I run this SQL will appear this error. 当我运行此SQL时,将出现此错误。 #1052 - Column 'syear' in where clause is ambiguous
. #1052 - Column 'syear' in where clause is ambiguous
。 any one give me answer. 有人给我答案。
SELECT c.course_id
, c.TITLE
, c.SHORT_NAME
, cs.overallmark
FROM courses c
, course_subjects cs
WHERE syear = '2010'
AND c.subject_id = cs.subject_id
ORDER
BY c.course_id
, c.TITLE
, c.SHORT_NAME
, cs.overallmark
Your query should look something like this: 您的查询应如下所示:
SELECT c.course_id, c.TITLE, c.SHORT_NAME, cs.overallmark
FROM courses c JOIN
course_subjects cs
ON c.subject_id = cs.subject_id
WHERE c.syear = 2010
ORDER BY c.course_id, c.TITLE, c.SHORT_NAME, cs.overallmark;
Notes: 笔记:
FROM
clause. 请勿在FROM
子句中使用逗号。 Always use proper, explicit JOIN
syntax. 始终使用正确的显式JOIN
语法。 syear
is stored as a number not a string. 我假设syear
存储为数字而不是字符串。 Do not put quotes around string constants. 不要在字符串常量两边加上引号。 You have a column named syear
in both your tables and the DB engines does not know which one to pick. 您的表中都有一列名为syear
的列,并且数据库引擎不知道选择哪一个。
Add the table name before it 在表名之前添加
course_subjects.syear
Besides that you should not use the old implicit join syntax any more. 除此之外,您不应再使用旧的隐式联接语法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.