mysql coalesce
#Avoid sum null
SELECT SUM(COALESCE(field_with_null_values, 0)) as s FROM tablename
#Avoid concat string null
SELECT CONCAT(name_never_null, ' ', COALESCE(surname_with_null_values, '')) as complete_name FROM users
3.6
5
The COALESCE() function returns the first non-null value in a list.
Example : SELECT COALESCE(NULL, NULL, 'W3Schools.com', NULL, 'Example.com');
output : 'W3Schools.com'
Thank you!
5
0
Are there any code examples left?
New code examples in category SQL