SQLite IFNULL() Function
Example
Return 'No value' when the value is NULL:
SELECT IFNULL(NULL, 'No value');
Try it Yourself »
Definition and Usage
The IFNULL() function returns the first argument if it is not NULL, else the second argument.
Tip: Also look at COALESCE(), NULLIF().
Syntax
IFNULL(value, alternative)
Parameter Values
| Parameter | Description |
|---|---|
| value | Required. The value to test |
| alternative | Required. The value to return if value is NULL |
Technical Details
| Return type: | Same as the returned value |
|---|
More Examples
Example
Show 'No orders' for the customers without orders:
SELECT Customers.CustomerName,
IFNULL(Orders.OrderID, 'No orders')
FROM Customers
LEFT JOIN Orders
ON Customers.CustomerID = Orders.CustomerID;
Try it Yourself »