I have this table called Customers
:
id | name | code
----------------
1 | A | 1
2 | B | 2
3 | C | 3
4 | D | 4
My idea is to update a list of name
like:
A,B,D
With the value 1
, and to have:
id | name | code
----------------
1 | A | 1
2 | B | 1
3 | C | 3
4 | D | 1
How can I update code
for a list of name
?
I could do this:
UPDATE Customers
SET code=1
WHERE name='A'
OR name='B'
OR name='D';
But the list is big, like 45.000 names.
Is there another way to make that querie?
CodePudding user response:
You can do
UPDATE Customers
SET code=1
WHERE name IN ('A', 'B', 'D');
Or if you have too many records maybe something like this would be better :
UPDATE Customers
SET code=1
WHERE name NOT IN ('C','E');