[MySql] FIND_IN_SET() function

Objectif: update multiple rows in mysql

Quick Solution (for example):

UPDATE my_table SET my_field=first_value WHERE id=1;
UPDATE my_table SET my_field=second_value WHERE id=2;
UPDATE my_table SET my_field=third_value WHERE id=3;

Problem : performance

Other solution with function FIND_IN_SET() :

UPDATE `my_table`
SET my_field = find_in_set(id, 'first_value, second_value, third_value, ...')
WHERE id IN (1, 2, 3, 4, ...)

Find more explaination :

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s