How To Concat With Null Fields In MySQL
Posted by Weston Ganger
I needed to
CONCAT a string in MySQL statement but it had null values which where wrecking the statement. Turns out you need to use
CONACT_WS instead. This allows NULL values to be treated as empty strings as you would expect
# Fails CONCAT('', 'foo', 'bar', NULL) = NULL # Allows any null values CONCAT_WS('', 'foo', 'bar', NULL) = 'foobar'
Related External Links: