Вопрос

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;
Это было полезно?

Решение

Try syntax like

update likes SET
active = case when active = 1 then 0 else 1 end 
where uuid=11 and scene_id=2;

Другие советы

Since you're using MySql, you could also do the following:

update likes 
set active = !active 
where uuid=11 and scene_id=2;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top