Search code examples
mysqlwhere-in

Update a column on rows of which another column has multiple values


I am having trouble with something like this:

UPDATE `database` SET `col1` = 0 WHERE `col2` in (1,2,3,4);

Following is an actual failed query.

Error Message:
1064: 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 '@cc3.biz, sales@allservico.com)' at line 1

SQL:

UPDATE `CubeCart_customer` SET `optIn1st` = 0 WHERE `email` in (markscarts@cc3.biz, sales@allservico.com);

I have searched the web, and here, and tried several variations in my code to produce the query, but I just can't pinpoint where I'm failing.

Any light on this matter would be greatly appreciated.


Solution

  • You need quotes around your string values

    UPDATE CubeCart_customer 
    SET optIn1st = 0
    WHERE email in ('markscarts@cc3.biz', 'sales@allservico.com');