Share the post "Toggle 1 And 0 Values In An Update MySQL Statement"
Good thing MySQL has the IF() function that enables us to update a column by switching values to 0 if current value is 1 and vice versa in just 1 query.
|
1 |
UPDATE table_name SET column_name = IF(column_name = 1, 0, 1) WHERE column_name = whatever |
This way, we do not have to waste resources by querying for the current value and then executing an update query.