Sql - COALESCE and NULLIF
📖 Read the lesson
Code Life
By Pierre Marsaa
NULL spreads
Remember Shadowchu's missing power?
NULL
does not just sit there quietly:
any calculation involving NULL gives NULL
.
↗️
Loading editor...
↶
▶️ Run
↷
COALESCE
returns the
first non-NULL value
among its arguments. Give it a fallback and the NULL disappears:
↗️
Loading editor...
↶
▶️ Run
↷
As many arguments as you like
COALESCE(a, b, c, ...)
checks the values from left to right and returns the first one that is not NULL. If they are all NULL, the result is NULL.
Verify