IFNULL()
IFNULL(condition,result)
This function returns the results of the
condition given in the first argument of
the function if its results are not NULL. If the condition results are
NULL, the results of the expression or string given in the second
argument are returned. It will return a numeric or a string value
depending on the context:
SELECT CONCAT(name_first, SPACE(1), name_last) AS Client, telephone_home AS Telephone, IFNULL(goals, 'No Goals Given') AS Goals FROM clients LIMIT 2; +----------------+-----------+----------------+ | Client | Telephone | Goals | +----------------+-----------+----------------+ | Janice Sogard | 835-1821 | No Goals Given | | Kenneth Bilich | 488-3325 | Long Term | +----------------+-----------+----------------+
This SQL statement provides a list of clients and their
telephone numbers, along with their investment goals. If the client
never told the broker of an investment goal (i.e., the
goals column is NULL), the text “No Goals Given” is
displayed.