Revision
Comparisons with NULL
Functions with NULL
COALESCE to the rescue
19. COALESCE with more than two parameters
NULLIF
Revision and practice

Instruction

Good job. The last thing you should know about COALESCE is that it can take more than two arguments. It will simply look for the first non-NULL value in the list and return it.

COALESCE(name, CAST(id AS varchar), 'n/a')

The above function will try to show the name of a given product. If the name is unknown, it will try to show its id instead. If the id is unknown too, it will simply show 'n/a'.

Exercise

Show the name of each product together with its type. When the type is unknown, show the category. When the category is missing, too, show 'No clue what that is'.

Console

Code editor

Result

TableConsole