SQL
Handle NULL Values in SQL with COALESCE
Learn how to use the COALESCE function in SQL to return the first non-NULL expression from a list, providing default values for potentially empty columns.
SELECT
product_name,
COALESCE(description, 'No description available') AS product_description,
price
FROM products;
How it works: The COALESCE function is a standard SQL function that evaluates arguments in order and returns the first expression that is not NULL. It's incredibly useful for providing fallback or default values when a column might contain NULLs, ensuring your output is always readable and consistent. In this snippet, if `description` is NULL, 'No description available' will be displayed instead.