Sai
Sai

Reputation: 841

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 = '[email protected]', '[email protected]', '[email protected]';

Upvotes: 2

Views: 7887

Answers (2)

Chetan Gawai
Chetan Gawai

Reputation: 2401

Note to add ; at the end

UPDATE `email-database`
SET customerEmail = ''
WHERE customerEmail in ('[email protected]', '[email protected]', '[email protected]');

Upvotes: 0

e4c5
e4c5

Reputation: 53734

Use IN

UPDATE `email-database`
SET customerEmail = ''
WHERE customerEmail IN ( '[email protected]', '[email protected]', '[email protected]')

Upvotes: 3

Related Questions