Ad space (banner)
🗄️SQL Lessons
Lesson 45 / 50

Substituting NULL with COALESCE

This lesson covers substituting a fallback value for NULL using COALESCE, so displayed data looks clean. It's for anyone searching "SQL COALESCE tutorial."

COALESCE(column, fallback) returns a fallback value whenever a column is NULL — perfect for something like showing "Not provided" wherever a phone number is missing.

The example uses COALESCE(phone, 'Not provided') to display "Not provided" in place of Bob's NULL phone number. The key idea: the underlying data is untouched — only the displayed value gets substituted.

A common early mistake is not realizing COALESCE can take more than two arguments — list three or more, and it returns the first one that isn't NULL, reading left to right, which is handy when you have several fallback candidates to try in order. This is an extremely common function in practice, for converting a raw NULL into something presentable right before it hits the screen — especially valuable in databases full of optional fields, like member or product records.

SQL
OUTPUT

💡 The SQL engine may take a few seconds to load the first time you run code.

Ad space (banner)
Ad space (in-article)