Reputation: 3675
I have two following update statements:
update tb1
set col1=1
where id in ('1', '2', '3')
update tb1
set col1=0
where id not in ('1', '2', '3')
Can I combine above two update statements into one?
Upvotes: 2
Views: 3541
Reputation: 21
UPDATE tb1
SET col1 = CASE WHEN id in (1, 2, 3)
THEN 1
WHEN id NOT IN (1, 2, 3)
THEN 0
ELSE
col1
END ;
Upvotes: 2
Reputation: 7695
Try this:
UPDATE tb1 SET col1= CASE WHEN id in ('1', '2', '3') THEN 1 ELSE 0 END
Upvotes: 6