Toggle a MySQL field between 0 and 1

Here's a simple example of how to toggle an integer (most often a tinyint in my case) field in MySQL between 0 and 1:

UPDATE table SET int_field=MOD(int_field+1,2) WHERE id=123
Andrew Apr 1, 2012

could also do: UPDATE table SET int_field=!int_field WHERE id=123

benjamin Aug 25, 2012

tanks bunch. very usefull

Leave a Comment