Reputation: 99
I want to update status, but using one query !!
UPDATE myTable SET `status` = 0 WHERE `name` IN ('a', 'b', 'c', 'd')
UPDATE myTable SET `status` = 1 WHERE `name` NOT IN ('a', 'b', 'c', 'd')
Upvotes: 3
Views: 1161
Reputation: 18600
You can use CASE statement.
UPDATE myTable
SET status = (CASE
WHEN `name` IN ('a','b','c','d') THEN '0'
WHEN `name` NOT IN ('a','b','c','d') THEN '1'
END);
Upvotes: 6
Reputation: 9693
Make 'status' datatype boolean, default value 0 and for "name NOT IN ('a', 'b', 'c', 'd')
"
use
UPDATE myTable SET `status` = 1 WHERE `name` NOT IN ('a', 'b', 'c', 'd');
You do not have to run two queries.
Upvotes: 0