Here we will learn Coalesce() function in sqlite and how to use SQLite Coalesce() function to return first non-null argument from multiple arguments with examples.
In SQLite Coalesce() function will take two or more arguments and return the first non-NULL argument value.
The SQLite Coalesce() function must have atleast 2 arguments and it will return NULL value in case if all the argument values are NULL.
Following is the syntax of SQLite Coalesce() function to return first non-NULL argument value.
In SQLite Coalesce() function we defined few parameters those are
param1, param2, ... paramn – These are the parameters which are used to test for the first non-NULL value. The SQLite Coalesce() function must have atleast 2 parameters.
Now we will see how to use SQLite coalesce() function to get first non-NULL value
The following are the simple examples of SQLite coalesce() function to get the first non-NULL argument value from multiple arguments.
sqlite> SELECT coalesce(NULL,NULL,09,'Tutlane');
coalesce(NULL,NULL,09,"Tutlane")
-------------------------------
9
sqlite> SELECT coalesce(NULL,NULL,NULL);
coalesce(NULL,NULL,NULL)
-------------------------------
NULL
sqlite> SELECT coalesce('Tutlane',NULL,NULL);
coalesce("Tutlane",NULL,NULL)
-------------------------------
Tutlane
This is how we can use SQLite Coalesce() function to get the first non-NULL argument value from multiple arguments based on our requirements.