Function Reference

IFNULL

PostgreSQL equivalent:

Replaces NULL with the given value.

MySQL 8.1
IFNULL(value, alternative_value)

Parameters

value
Value to check
alternative_value
Value returned if value is NULL

Return value

value if it is not NULL, otherwise alternative_value

Examples

Replacing NULL with a value

MySQL 8.1
SELECT IFNULL(NULL, 'Alternative value');
IFNULL(NULL, 'Alternative value')
Alternative value

Replacing a missing middle name

MySQL 8.1
SELECT last_name,
	first_name,
	IFNULL(middle_name, 'not specified') AS middle_name
FROM Teacher
WHERE id BETWEEN 9 AND 12;
last_namefirst_namemiddle_name
OstrozhskayaViktoriyaNikolaevna
KrylovYUrijnot specified
EvseevAndrejnot specified
MoiseevBogdanRomanovich

Details

Unlike COALESCE, it takes exactly two arguments.

See also

Where to learn