Mysql if condition in update query
We can use the IF CONDITION in update query, given blow example will show how we can use the IF Condition in update query.
Suppose we have a table that has 2 column first is Name and second is Gender, structure of the table is given below.
Name |
Gender |
Sumit |
m |
Barkha |
f |
Vasu |
m |
Neelam |
f |
In the above table we will update the gender column and replace ‘m’ with ‘f’ and ‘f’ with ‘m’.
Query are as follows:
UPDATE table SET gender = IF(gender = ‘m’, ‘f’, ‘m’);