'MySQL, change true values to false and false values to true. How? [duplicate]

I need to change a column in a table in my mysql database so that the values in the column that are currently true change to false, and the values that were false before to true.

So, before: Value A: false Value B: true

After: Value A: true Value B: false

How do I do this? Trying to write a liquibase migration for this. I first thought of something like:

UPDATE tableA SET columnA = false where columnA = true, SET columnA = true where columnA = false;

But I realized that if I first change the true values to false, then all values will be false, and then MySQL will flip everything from false to true. Obviously not what I want.

Any ideas?



Solution 1:[1]

You can make a CASE WHEN

UPDATE tableA SET columnA = CASE columna WHEN false then  true
ELSE false ENd;

If you have more nested conditions, it is not problem to expand the conditions

Solution 2:[2]

This is what you need:

UPDATE tableA SET columnA = NOT columnA;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 lemon