[MySQL] Select the first non-NULL value with COALESCE()

Created on November 30, 2026

COALESCE() checks its arguments in order and returns the first non-NULL value.

SELECT COALESCE(NULL, NULL, 'default value') AS result;
default value

You can also supply a fallback for a nullable column.

SELECT COALESCE(name, 'no name') FROM users;

Each row with a NULL name returns no name. Other rows return the value of name.

MySQL