MySQL: Simple way to toggle a value of an int field

前端 未结 9 1612
忘掉有多难
忘掉有多难 2021-01-30 10:19

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 S         


        
9条回答
  •  执笔经年
    2021-01-30 11:10

    In this case, you could use an XOR type operation:

    UPDATE some_table SET an_int_value = an_int_value XOR 1
    

    This is assuming that an_int_value will always be 1 or 0 though.

提交回复
热议问题