Mysql bulk UPDATE

Run the following statement for bulk UPDATE

UPDATE table1 SET column2 = CASE 
WHEN column1 = 'A' THEN 'AB'
WHEN column1 = 'B' THEN 'BC'
WHEN column1 = 'C' THEN 'CD'
ELSE column2 
END;

Make sure you included ELSE statement, if you skip it then it will NULL rest of the column2 fields.
So, if you have any pre-filled column2 field and you want to keep their values then use ELSE column2 to keep them.

Leave a Reply