Reputation:
I want to toggle the activate column in my table; I think it can be done with case statement! I have tried following but apparently it does not work and there is a syntax problem; could you please let me know if it can be done with one statement like the following:
update likes l case when active = 1 then set active=0 else set active=1 end where l.uuid=11 and l.scene_id=2;
Upvotes: 0
Views: 29
Reputation: 62861
Since you're using MySql
, you could also do the following:
update likes
set active = !active
where uuid=11 and scene_id=2;
Upvotes: 0
Reputation: 26177
Try syntax like
update likes SET
active = case when active = 1 then 0 else 1 end
where uuid=11 and scene_id=2;
Upvotes: 2