In MySql, Your update query will not run as expected when concatenating a column which has null value. Query doesn't show any issues but the value will not be updated.

Example:
SELECT * FROM `dump` 
mysql table
When we run the update query our result will be:
update dump set content=concat(content,'updated content') where id=1;
0 rows affected. (Query took 0.0000 sec)
To fix this issue we can use IFNULL IFNULL  function takes two values and returns first value if it is not null otherwise it returns second value. So to make our update query work we have to modify like this:
update dump set content=concat(ifnull(content,''),'updated content') where id=1;

 


Comments (0)
Leave a Comment

loader Posting your comment...