简体   繁体   English

#1052-where子句中的“年”列不明确

[英]#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: 笔记:

  • Never use commas in the FROM clause. 请勿FROM子句中使用逗号。 Always use proper, explicit JOIN syntax. 始终使用正确的显式JOIN语法。
  • Qualify all column names, especially when a query references more than one table. 限定所有列名,尤其是当查询引用多个表时。
  • I assume that 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.

相关问题 #1052 - where 子句中的列“bookingId”不明确 - #1052 - Column 'bookingId' in where clause is ambiguous 错误 1052 (23000):where 子句中的列“course_id”不明确 - ERROR 1052 (23000): Column 'course_id' in where clause is ambiguous 违反完整性约束:1052列和where子句不明确 - Integrity constraint violation: 1052 Column and in where clause is ambiguous 完整性约束违规:1052 where子句中的列'id'不明确 - Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous 错误代码:1052。where子句中的列“ datetime”不明确 - Error Code: 1052. Column 'datetime' in where clause is ambiguous MySQL错误:冲突:1052 where子句不明确的列'created_at' - Mysql error: violation: 1052 Column 'created_at' in where clause is ambiguous' 错误 1052:where 子句中的列“metric_name”不明确 - Error 1052: Column 'metric_name' in where clause is ambiguous MySQL错误#1052 from子句中的列不明确 - MySQL Error #1052 Column in from clause is ambiguous SQLSTATE [23000]:违反完整性约束:1052 where 子句中的列“值”不明确 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'value' in where clause is ambiguous Laravel Eloquent SQLSTATE[23000]:违反完整性约束:1052 列...在 where 子句中不明确 - Laravel Eloquent SQLSTATE[23000]: Integrity constraint violation: 1052 Column ... in where clause is ambiguous
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM