This SQLite post explains how to use the SQLite coalesce function with syntax and examples.
The SQLite coalesce function returns the first non-null expression in the list.
The syntax for the coalesce function in SQLite is:
coalesce( expression1, expression2, ... expression_n )
The expressions to test for non-null values. At least 2 expressions must be provided.
The coalesce function can be used in the following versions of SQLite:
Let's look at some SQLite coalesce function examples and explore how to use the coalesce function in SQLite.
For example:
sqlite> SELECT coalesce(null, null, null, 'A', 'B');
Output: 'A'
sqlite> SELECT coalesce('A', 'B', null, 'C', 'D');
Output: 'A'
sqlite> SELECT coalesce(null, 1, 2, 3, null, 4);
Output: 1
sqlite> SELECT coalesce(null, 'AODBA.com');
Output: 'AODBA.com'
sqlite> SELECT coalesce(null, 'AODBA.com', 'mysite.com');
Output: 'AODBA.com'
sqlite> SELECT coalesce(null, null, null, null, null);
Output: NULL