MySQL Concat NULL columns

When you want to combine values of multiple columns, CONCAT function comes to help. It’s very straightforward until one of the columns can contain NULL values.
For example if column column1 is NULL and column2 is ‘Hello’, following query

SELECT CONCAT(column1, column2) FROM test WHERE id = 1

will return NULL. Sad face.

There are multiple solutions to this, but most easy one is to use COALESCE function. It will return first non-NULL value of a list. In this case, it will return empty string if column1 is NULL.
So query

SELECT CONCAT(COALESCE(column1,''), column2) FROM `test` WHERE id = 1

will return ‘Hello’. Success!
If both columns can contain NULL values, then use

SELECT CONCAT(COALESCE(column1,''), COALESCE(column2,'')) FROM `test` WHERE id = 1

and so on.