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’);


To seek challenging roles and to achieve excellence in the field of Open Source Web Technology with a profound spirit of commitment and dedication.

Share This Post

Related Articles

© 2017 Sumit Bansal. All rights reserved. Site Admin · Entries RSS · Comments RSS
Powered by WordPress · Designed by Theme Junkie