Mysql

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 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts