MySQL compare NULL equivalent to an empty string

Nearly all MySQL’s string functions return NULL when a NULL value is used for comparison. Although this is correct sometimes it is useful to compare NULL as being equalivalent to an empty string (although they are technically different).

One exception in MySQL’s string functions is the CONACT_WS function as this skips NULL parameters after the separator argument.

This means it can be used like this to compare NULL as being equal to an empty string:

CONCAT_WS('',value1) = CONCAT_WS('',value2)

This will return true if value1 and value2 are any combination of NULL and empty string.

Leave a Reply