Monday, October 15, 2012

Update new values for existing MySql fields without Overwriting

While updating the existing MySql table field value you may wish to preserve existing field value or my prefer to update without overwriting with new value. You may think of writing PHP code for getting existing value and append and store it to database with new value.

But there is a MySql concat() function. So you can append the your new value dynamically, function having following  pattern:



mysql_query("UPDATE `table_name` SET `field_name`=concat(`field_name`, ", new_value") WHERE `id_is`='3450';


id_is    ||  field_name

22       ||  (value+new_value)