Reputation: 17301
In the below Update
command i want to set all delay
field to 0
and an id
of 2
must be update to 1
UPDATE `tsms_entry_exit`
SET `delay`=(
CASE `delay`
WHEN `id` = 2 THEN 1
ELSE 0
END
)
WHERE user_id = 1
Otherwise:
UPDATE `tsms_entry_exit`
SET `delay`=0
WHERE user_id = 1;
UPDATE `tsms_entry_exit`
SET `delay`=0
WHERE user_id = 1 AND id = 2
How do i update twice in one update command?
Upvotes: 0
Views: 68
Reputation: 18600
If I understand very well, might be you want this
UPDATE `tsms_entry_exit`
SET `delay`= CASE WHEN `id` = 2 THEN 1
ELSE 0
END
WHERE user_id = 1
Upvotes: 1
Reputation: 44844
This is how you can use the update command
update tsms_entry_exit set
delay =
case when id = 2 then 1
else 0
end
where user_id = 1
Upvotes: 0