SQL NULL Functions
SQL IFNULL(), ISNULL(), COALESCE(), and NVL() Functions
![demo supplier table](./images/Null 3.png)
Suppose that the "City" column is optional, and may contain NULL values.
Look at the following SELECT statement:
Example
SELECT Supplier_name, Address * (City + Pincode) FROM supplier;You can click on above box to edit the code and run again.
Output
![demo supplier table](./images/Null 2.png)
Solutions in MySQL
The MySQL IFNULL() function lets you return an alternative value if an expression is NULL:
Example
SELECT Supplier_name, Address * (City + IFNULL(Pincode, 0 )) FROM supplier;
or we can use the COALESCE() function:
Example
SELECT Supplier_name, Address * (City + COALESCE(Pincode, 0 )) FROM supplier;
Solution in SQL server
The MySQL ISNULL() function lets you return an alternative value if an expression is NULL:
Example
SELECT Supplier_name, Address * (City + ISNULL(Pincode, 0 )) FROM supplier;
or we can use the COALESCE() function:
Example
SELECT Supplier_name, Address * (City + COALESCE(Pincode, 0 ))
FROM supplier;
Solution in MS Access
The MS Access IsNull() function returns TRUE (-1) if the expression is a null value, otherwise FALSE (0):
Example
SELECT Supplier_name, Address * (City + IIF(IsNull(Pincode), 0 , Pincode)) FROM supplier;