【问题标题】:"Insert into where" statement error“插入到哪里”语句错误
【发布时间】:2014-11-21 10:24:52
【问题描述】:

我有一个不断返回错误的 mysql 查询

错误:

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 ' iOS= 0, Android= 0, sport IN (football,tennis,' at line 2

整个查询是

INSERT INTO table2
SELECT *
FROM table1
WHERE iOS = 0
    , android = 0
    , sport IN (football,tennis,golf)

(iOS 和 android 列是布尔值,而运动是 VARCHAR

该查询旨在获取 iOS/android 列为 0 且运动列值为足球或网球或高尔夫的所有条目。

哪里出错了?感谢您的帮助

【问题讨论】:

  • 使用AND 代替逗号来构建您的条件

标签: mysql


【解决方案1】:

使用ANDOR 包含更多条件。

文字字符串使用引号分隔:

INSERT INTO table2
SELECT * FROM table1
WHERE iOS = 0
AND android = 0
AND sport IN ('football', 'tennis', 'golf')

【讨论】:

    【解决方案2】:

    只需输入 insted of ,(逗号)并在单引号中写下运动名称

    INSERT INTO table2 SELECT * FROM table1 WHERE `iOS` = 0 and android = 0 and (sport IN ('football','tennis','golf'))
    

    【讨论】:

      【解决方案3】:

      您的WHERE 声明是错误的。您必须在子句之间添加AND 条件。

      WHERE iOS = 0 AND android = 0 AND sport IN ('football', 'tennis', 'golf')
      

      【讨论】:

      • 当我将其更改为“and”时,我收到错误 Error: Unknown column 'football' in 'where Clause'
      • 一个问题解决了,还有更多……引用你的字符串。
      • 为括号内的值添加引号。
      猜你喜欢
      • 1970-01-01
      • 2013-05-17
      • 1970-01-01
      • 1970-01-01
      • 2017-08-03
      • 1970-01-01
      • 2014-05-25
      相关资源
      最近更新 更多