Appending data into a MySQL field, additionally with a "NULL" check

Some times we need to append data into a mysql field. So here is solution. Also the query below checks if the value is NULL then if first enters the empty data to the table field.

UPDATE employee SET notes=CONCAT(COALESCE(notes, ''), 'NewDataHere') where employeeID=13;


In the above query concat('','') is to append the new data to the existing data of the field notes. Other function COALESCE(",") checks for NULL, if the field have NULL value then it will enter an empty '' value to field. Other wise in case of NULL value concat() function will end up with a MySQL error.

Hope this will be helpful, comments, suggestions and other coding tricks are most welcome.

Posted in |