Skip to main content
SQL โ€ข LESSON 119

COALESCE

How can we replace NULL values with a default fallback string?

Advancedโฑ 3 Minutesโญ 1320 XP
๐Ÿค” THE QUESTION

How can we replace NULL values with a default fallback string?

๐Ÿ’ก WHAT IS IT?

COALESCE returns the first non-NULL expression from its arguments.

๐ŸŽฏ WHAT IS IT USED FOR?

Replacing null phone numbers, default customer names, preventing UI null crashes.

๐Ÿ’ป EXAMPLE
SELECT
name,
COALESCE(phone, 'Unknown') AS phone
FROM employees;

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for COALESCE.

  • โœ“ COALESCE
  • โœ“ Default fallback
  • โœ“ Null replacement
  • โœ“ Data formatting