SQLBeginner#functions

What is the difference between COALESCE and CASE?

COALESCE returns the first non-NULL argument, a shorthand for NULL handling. CASE evaluates arbitrary conditions and returns different values, so it handles any branching logic.

Example
SELECT COALESCE(nickname, first_name, 'guest') AS label,
       CASE WHEN salary > 100000 THEN 'high'
            WHEN salary > 50000 THEN 'mid'
            ELSE 'entry' END AS band
FROM employees;

Related Questions

1
SQLAdvanced#windows

What is a window function?

Open
2
SQLAdvanced#windows

Difference between ROW_NUMBER, RANK and DENSE_RANK?

Open
3
SQLAdvanced#windows

What do LAG and LEAD do?

Open