SQL provides several functions to work with NULL values.
product_code | product_name | price | order_units |
---|---|---|---|
1 | Ipad | 100 | 56 |
2 | Tablet | 42 |
These are not functions but logical operators to check if a value is NULL or not.
SELECT column_name FROM table_name WHERE column_name IS NULL;
Returns expr2 if expr1 is NULL, otherwise returns expr1.
SELECT IFNULL(column_name, 'Default') AS result FROM table_name;
Returns the first non-NULL expression in the list.
SELECT COALESCE(column1, column2, 'Not Available') AS result FROM table_name;
Returns NULL if expr1 equals expr2, otherwise returns expr1.
SELECT NULLIF(column1, 0) AS result FROM table_name;