Posted on

How to deal with NULLs in a result set, making them readable

A commonly asked question… and you could do IFNULL(col,'wazzanull') or somesuch.
But there’s another standard SQL function with a funny (and therefore difficult to remember) name, and that is COALESCE(). The COALESCE function takes one or more parameters, and will return the first one that is not NULL. GooD huh? Example:
SELECT COALESCE(somecol,anothercol,'no values available) AS colalias

And for the linguistically curious, here’s what the English dictionary says about the word:
1. To grow together; fuse.
2. To come together so as to form one whole; unite

Posted on