| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 | [role="xpack"][testenv="basic"][[sql-functions-conditional]]=== Conditional FunctionsFunctions that return one of their arguments by evaluating in an if-else manner.[[sql-functions-conditional-coalesce]]==== `COALESCE`.Synopsis[source, sql]----COALESCE ( expression<1>, expression<2>, ... )----*Input*:<1> 1st expression<2> 2nd expression...**N**th expressionCOALESCE can take an arbitrary number of arguments.*Output*: one of the expressions or `null`.DescriptionReturns the first of its arguments that is not null.If all arguments are null, then it returns `null`.["source","sql",subs="attributes,callouts,macros"]----include-tagged::{sql-specs}/docs.csv-spec[coalesceReturnNonNull]----["source","sql",subs="attributes,callouts,macros"]----include-tagged::{sql-specs}/docs.csv-spec[coalesceReturnNull]----[[sql-functions-conditional-ifnull]]==== `IFNULL`.Synopsis[source, sql]----IFNULL ( expression<1>, expression<2> )----*Input*:<1> 1st expression<2> 2nd expression*Output*: 2nd expression if 1st expression is null, otherwise 1st expression..DescriptionVariant of <<sql-functions-conditional-coalesce>> with only two arguments.Returns the first of its arguments that is not null.If all arguments are null, then it returns `null`.["source","sql",subs="attributes,callouts,macros"]----include-tagged::{sql-specs}/docs.csv-spec[ifNullReturnFirst]----["source","sql",subs="attributes,callouts,macros"]----include-tagged::{sql-specs}/docs.csv-spec[ifNullReturnSecond]----[[sql-functions-conditional-isnull]]==== `ISNULL`.Synopsis[source, sql]----ISNULL ( expression<1>, expression<2> )----*Input*:<1> 1st expression<2> 2nd expression*Output*: 2nd expression if 1st expression is null, otherwise 1st expression..DescriptionVariant of <<sql-functions-conditional-coalesce>> with only two arguments.Returns the first of its arguments that is not null.If all arguments are null, then it returns `null`.["source","sql",subs="attributes,callouts,macros"]----include-tagged::{sql-specs}/docs.csv-spec[isNullReturnFirst]----["source","sql",subs="attributes,callouts,macros"]----include-tagged::{sql-specs}/docs.csv-spec[isNullReturnSecond]----[[sql-functions-conditional-nvl]]==== `NVL`.Synopsis[source, sql]----NVL ( expression<1>, expression<2> )----*Input*:<1> 1st expression<2> 2nd expression*Output*: 2nd expression if 1st expression is null, otherwise 1st expression..DescriptionVariant of <<sql-functions-conditional-coalesce>> with only two arguments.Returns the first of its arguments that is not null.If all arguments are null, then it returns `null`.["source","sql",subs="attributes,callouts,macros"]----include-tagged::{sql-specs}/docs.csv-spec[nvlReturnFirst]----["source","sql",subs="attributes,callouts,macros"]----include-tagged::{sql-specs}/docs.csv-spec[nvlReturnSecond]----[[sql-functions-conditional-nullif]]==== `NULLIF`.Synopsis[source, sql]----NULLIF ( expression<1>, expression<2> )----*Input*:<1> 1st expression<2> 2nd expression*Output*: `null` if the 2 expressions are equal, otherwise the 1st expression..DescriptionReturns `null` when the two input expressions are equal andif not, it returns the 1st expression.["source","sql",subs="attributes,callouts,macros"]----include-tagged::{sql-specs}/docs.csv-spec[nullIfReturnFirst]----["source","sql",subs="attributes,callouts,macros"]----include-tagged::{sql-specs}/docs.csv-spec[nullIfReturnNull]----
 |