SQLite Coalesce() Function

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.

SQLite Coalesce() Function

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.

Syntax of SQLite Coalesce()

Following is the syntax of SQLite Coalesce() function to return first non-NULL argument value.

 

coalesce(param1, param2, ... paramn)

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

SQLite Coalesce() Function Examples

The following are the simple examples of SQLite coalesce() function to get the first non-NULL argument value from multiple arguments.

 

sqliteSELECT coalesce(NULL,NULL,09,'Tutlane');

 

coalesce(NULL,NULL,09,"Tutlane")

-------------------------------

9

 

sqliteSELECT coalesce(NULL,NULL,NULL);

 

coalesce(NULL,NULL,NULL)

-------------------------------

NULL

 

sqliteSELECT 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.