MySql concat null values
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:
When we run the update query our result will be:
Example:
SELECT * FROM `dump`
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)