“插入到哪里”语句错误

时间:2014-11-21 10:24:53

标签: mysql

我有一个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列是布尔值,sport是VARCHAR

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

哪里出错?谢谢你的帮助

3 个答案:

答案 0 :(得分:2)

使用ANDOR包含更多条件。

Literal Strings使用引号分隔:

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

答案 1 :(得分:1)

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

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

答案 2 :(得分:1)

只需输入代替,(逗号)并在单引号中输入运动名称

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