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:

Article Topic:Software Development - Web Development

Date:February 16, 2017

Recommended Posts

Contact

604-309-8713
info@solidfoundationwebdev.com

Send Me A Message

I would love to get in touch and talk about your next project. Feel free to send a message and I will get back to you shortly.

Get Connected