I am trying to update column for three rows in sql. However when I run following query, only one row is affected. Can someone help me to see where I am making a mistake? Thank you!
update some_table
set date_updated = case some_id
when '7791' then '2021-10-08 06:59:05'
when '1555' then '2021-08-26 05:30:54'
when '363201' then '2021-08-31 05:01:45'
end
where some_id = ('7791, 1555, 363201')
and date_updated between '2021-11-01' and '2021-11-03';
CodePudding user response:
You missed IN
Clause
where some_id in ('7791' ,'1555' , '363201')
and date_updated between '2021-11-01' and '2021-11-03';
CodePudding user response:
update some_table
set date_updated =
case when some_id = '7791' then '2021-10-08 06:59:05'
when some_id = '1555' then '2021-08-26 05:30:54'
when some_id = '363201' then '2021-08-31 05:01:45'
end
where some_id IN ('7791', '1555', '363201')
and date_updated between '2021-11-01' and '2021-11-03';