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?
To replace, use the REPLACE() MySQL function. Since you need to update the table for this, use the UPDATE() function with the SET clause.
If you want to select only specific columns, replace the * with the names of the columns, separated by commas. The following statement selects just the name_id, firstname and lastname fields from the master_name table.
The MySQL BETWEEN OperatorThe BETWEEN operator selects values within a given range. The values can be numbers, text, or dates. The BETWEEN operator is inclusive: begin and end values are included.
UPDATE `table_name` is the command that tells MySQL to update the data in a table . SET `column_name` = `new_value' are the names and values of the fields to be affected by the update query.
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
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