COALESCE - Handling NULLs
COALESCE returns the first non-NULL value from a list of arguments.
It's perfect for providing default values:
If email is NULL, it shows 'No email' instead.
You can chain multiple fallbacks:
COALESCE(phone, mobile, 'No contact')This checks phone first, then mobile, then uses the default.
COALESCE is supported in all major SQL databases and is the standard way to handle NULLs in output.
Check your understanding
Use COALESCE to replace NULL department_id with 0.
Examples run on the employees sample database. Open any of them in the playground to experiment.