简体   繁体   English

WHERE子句附近的SQL语法错误

[英]SQL syntax error near WHERE clause

Can anyone tell me what's wrong in this query? 谁能告诉我这个查询有什么问题吗?

<cfquery name="activesurveys">
      SELECT surveys.id,
             surveys.name,
             surveys.description,
      WHERE  surveys.active= 1
        AND  surveys.showinpubliclist= 1
     FROM 
             surveys
</cfquery>
<cfreturn activesurveys>

When I execute this code it gives this error: 当我执行此代码时,会出现以下错误:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE surveys.active= 1 AND surveys.showinpubliclist= 1' at line 4" “您的SQL语法有错误;请在与MySQL服务器版本相对应的手册中找到在第4行'WHERE surveys.active = 1 AND surveys.showinpubliclist = 1'附近使用的正确语法”

I think your query should be: 我认为您的查询应为:

SELECT surveys.id,
    surveys.name,
    surveys.description
FROM surveys
WHERE surveys.active= 1
    AND surveys.showinpubliclist= 1

Basically, there's a , after the last field you want to select, which is wrong, and also there's the fact that FROM goes after SELECT and before WHERE ... 基本上,有一个,你要选择的最后一个字段,这是错误的,也有这样的事实后, FROM后进入SELECT和前WHERE ...

You need to re-order your statement a bit. 您需要对语句重新排序。 The FROM needs to be before the WHERE . FROM必须在WHERE之前。 And you have an extra comma after the last column in your SELECT . SELECT的最后一列之后还有一个逗号。 Should look something like this: 应该看起来像这样:

<cfquery name="activesurveys">
    SELECT surveys.id,
           surveys.name,
           surveys.description
    FROM  surveys
    WHERE surveys.active = 1
      AND surveys.showinpubliclist = 1
</cfquery>
<cfreturn activesurveys>

I don't know ColdFusion but the SQL Syntax is 我不知道ColdFusion,但是SQL语法是

SELECT surveys.id,
       surveys.name,
       surveys.description
FROM 
       surveys
WHERE  surveys.active= 1
       AND surveys.showinpubliclist= 1

Kill the comma from the end of the last column name "surveys.description," and move the FROM statement before WHERE clause. 从最后一个列名称“ surveys.description”的末尾杀死逗号,并将FROM语句移到WHERE子句之前。 Like this 像这样

SELECT colname, colname, colname
FROM tablename

WHERE condition...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM