Skip to main content

IFNULL

Accepts exactly two arguments and returns the first non NULL argument, can be used to substitute a default value for a NULL value.

The IFNULL function is equivalent to the COALESCE function with two arguments only, the COALESCE function can have more than two arguments.

See also:
[SELECT] [COALESCE] [NULLIF]


Syntax

SELECT IFNULL(expression1, expression2) FROM <multipartIdentifier>;

Arguments

expression
Two expressions of any data type which resolve to a NULL or non NULL value.

If both expression arguments are NULL, the IFNULL function returns NULL.

Return Value(s)

Returns the first non NULL value from the two expression arguments.


Examples

Replace a NULL value with a default value

SELECT name, ifnull(website, 'Not hosting a website') AS website 
FROM google.storage.buckets where project = 'stackql';

For more information, see https://www.sqlite.org/lang_corefunc.html#ifnull