Sfwd favicon 152

How To Concat With Null Fields In MySQL

Posted by Weston Ganger on February 16, 2017

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:


Posted in Web Development and Tagged with mysql sql 


Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts