Sai Sai - 2 months ago 9
SQL Question

How to update multiple values in one column using one sql query?

I am working with a huge user database and there are around 200 user emails I want to set to an empty value, is there a easy way to remove them all in one query? here is a simple idea of what the table looks like.

(also as there a lots of email, I dont want to looks for all the ids, i only have the emails to work with)

column1 | column2 | customerEmail | column4
1 email1
2 email2
3 email3


Here is what i was going for but i received syntax error when using it for multiple values.

UPDATE `email-database`
SET customerEmail = ''
WHERE customerEmail = 'test@gmail.com', 'test2@gmail.com', 'test3@gmail.com';

Answer

Use IN

UPDATE `email-database`
SET customerEmail = ''
WHERE customerEmail IN ( 'test@gmail.com', 'test2@gmail.com', 'test3@gmail.com')
Comments