Update a boolean to its opposite in SQL without using a SELECT

前端 未结 2 1579
终归单人心
终归单人心 2021-01-11 09:59

Is it possible to upgrade a bool field by telling it to update the field to the opposite of what it is without having to select the value - check it then update accordingly

相关标签:
2条回答
  • 2021-01-11 10:44

    use NOT

    UPDATE `table` SET `my_bool` = NOT my_bool
    
    0 讨论(0)
  • 2021-01-11 10:45
    UPDATE `Table` SET `my_bool` = 1 ^ `my_bool`
    
    0 讨论(0)
提交回复
热议问题