Depending on how you store the gender
column they may be a niftier trick available, but assuming it's a straight forward varchar
column the has the values M
and F
(or male
and female
- same logic), you could use a case
statement:
UPDATE employee
SET gender = CASE gender WHEN 'M' THEN 'F' WHEN 'F' THEN 'M' ELSE NULL END;
note:
Based on the "at most three values" statement in the OP's title, I'm assuming that null
s are allowed, and should remain unchanged. If this is not true, the case
expression could be simplified.