Next, let's look at how the
COALESCE() function can help with
NULLs. This is a standard SQL function also used in PostgreSQL.
COALESCE(x, y) function returns the first value that is not
NULL. Check out the example:
COALESCE(category, 'none') AS category
In this query, a product with an associated category will have its name and category shown. If there is a
NULL in a product's category field, the query will show "none" instead of a category name.
If you're wondering what the word "coalesce" means, it basically means "to come together, to form one group or mass." You can use coalesce literally (ingredients can coalesce into bread) or figuratively (ideas can coalesce).