Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
The COALESCE() function
8. Using COALESCE() with multiple parameters
The GREATEST() & LEAST() functions
The NULLIF() function
Summary

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.

SELECT COALESCE(name, id::char, 'n/a')
FROM product;

The above function will show a product name. If the name is unknown, it will show the product id instead. If both the name and id are unknown, it will simply show 'n/a'.

Exercise

Show each product's name and type. When the type is unknown, show the category. If the category is missing too, show 'No clue what that is'. Name the column type.

Stuck? Here's a hint!

Use this expression:

COALESCE(type, category, 'No clue what that is')