MySQL: Simple way to toggle a value of an int field
I know how to do this, but i think I'll overcomplicate it with double selects and so on.
How can you do this (example in pseudo-sql)
UPDATE some_table SET an_int_value = (an_int_value==1 ? 0 : 1);
It must be an int value due to some other functionality, but how do you do it in a simple way?
UPDATE table SET field = 1 - field
UPDATE some_table SET an_int_value = IF(an_int_value=1, 0, 1);
http://dev.mysql.com/doc/refman/5.1/en/control-flow-functions.html#function_if
UPDATE some_table SET an_int_value = IF(an_int_value=1, 0, 1)