Possible Duplicate:
Is there a way in MySQL to reverse a boolean field with one query?
To update (boolean) value normally we would check if it's set to false or true, and update it, I was wondering if there's query that would toggle boolean value.
You can use Boolean Operator for this Here delete is your boolean field. This solution also works for none boolean fields such as int and tinyint where values are set to 0 or 1.
To toggle a boolean, use the strict inequality (! ==) operator to compare the boolean to true , e.g. bool !== true . The comparison will return false if the boolean value is equal to true and vice versa, effectively toggling the boolean.
You can update boolean value using UPDATE command. If you use the BOOLEAN data type, MySQL internally convert it into tinyint(1). It can takes true or false literal in which true indicates 1 to tinyint(1) and false indicates 0 to tinyint(1).
UPDATE mytbl SET field = !field WHERE id = 42
Where 42
is the id
of the record, field
is the name of the boolean field and mytbl
is the table name.
You can use Boolean Operator for this Here delete is your boolean field.
update tab set `delete`=NOT `delete`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With