BeginnerCoder

Lesson 6 — COALESCE (nulls)

COALESCE: a fallback for missing values

NULL means "no value / unknown" — not 0, not empty text. COALESCE(a, b, c) returns the first argument that is not NULL, so it is perfect for fallbacks: show the nickname if there is one, otherwise the real name.

SELECT COALESCE(nickname, name) FROM users

In Python, NULL arrives as None.

Why it matters: NULLs leak into reports as blank cells or "None"; COALESCE keeps output clean and readable.

Want it another way?
Task

Use COALESCE so each user shows nickname, or name if nickname is NULL, and phone or 'no phone'.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.