Search code examples
mysqlsqlsql-update

In MySQL table update 'a' record with 'b' and 'b' with 'a'


In my table there are two field, one is name and other is gender. I want to fire query so that every male is update with female and viceversa.

I don't want to use procedure, trigger or function. I have to do this only with simple query.


Solution

  • In MSSQL you could do this:

    UPDATE table SET gender = CASE WHEN gender = 'M' THEN 'F' ELSE 'M' END
    

    If there is anything similar is My-SQL then this is one easy statement.