COALESCE() — Returns the first non-null argument, or null.
COALESCE( expression [, ... ] )
The COALESCE() function takes multiple arguments and returns the value of the first argument that is not null, or — if all arguments are null — the function returns null.
The following example uses COALESCE to perform two functions:
Replace possibly null column values with placeholder text
Return one of several column values
In the second usage, the SELECT statement returns the value of the column State, Province, or Territory depending on the first that contains a non-null value. Or the function returns a null value if none of the columns are non-null.
SELECT lastname, firstname, COALESCE(address,'[address unkown]'), COALESCE(state, province, territory), country FROM users ORDER BY lastname;