SQL coalesce takes two or more arguments and returns the first value that is not null or the SQL null value if all arguments are null.
SELECT COALESCE(first, second, 'default')
FROM …
The example returns the value of first if it is not null. Otherwise it returns the value of second if that is not null. Otherwise it returns the text default.
You can’t catch up on 20 years of SQL evolution in one day. Subscribe the newsletter via E-Mail, Bluesky or RSS to gradually catch up and to keep modern-sql.com on your radar.
About the Author
Markus Winand provides insights into SQL and shows how different systems support it at modern-sql.com. Previously he made use-the-index-luke.com, which is still actively maintained. Markus can be hired as trainer, speaker and consultant via winand.at.