MySQL coalesce Function Handy for Outer Joins and Nulls

The built-in function coalesce in MySQL is great for outer joins where the return or expected answer can be null. Coalesce can be used anytime a null could be expected. It accepts a comma-delimited list of values or column names and returns the 1st in the list that isn’t null.

This example below will return the value of column_1 if it’s not null, otherwise, it will return 1.

Leave a Reply

Your email address will not be published. Required fields are marked *