©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The NULLIF SQL Function in MySQL and MariaDB - Returns NULL if expressions are equal

NULLIFSyntax:NULLIF(Expression 1, Expression 2)
Return value:Depending on the data types used
Function type:NULL function
Function Description

The NULLIF() function returns NULL if "Expression 1" is equal to "Expression 2".

If "Expression 1" is not equal to "Expression 2", NULLIF() returns "Expression 1".

Where, if "Expression 1" is true, 1 is returned, if false, 0 is returned.

If "Expression 1" is NULL, the function will always return NULL.

SQL Examples for the NULLIF function

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15

SELECT nullif('ok''ok');
SELECT nullif('ok''ok2');

SELECT nullif(1, 1);
SELECT nullif(3, 4);

SELECT nullif(truetrue);
SELECT nullif(truefalse);
SELECT nullif(falsetrue);

SELECT nullif(1, null);
SELECT nullif(null, 1);
SELECT nullif(nullnull);

nullif('ok', 'ok')
varchar(2) BINARY
NULL
nullif('ok', 'ok2')
varchar(2) BINARY
ok
nullif(1, 1)
int(1)
NULL
nullif(3, 4)
int(1)
3
nullif(true, true)
int(1)
NULL
nullif(true, false)
int(1)
1
nullif(false, true)
int(1)
0
nullif(1, null)
int(1)
1
nullif(null, 1)
NULL
nullif(null, null)
NULL
The examples were created with the MyWAY SQL manager: Download

How to use the NULLIF() function in MySQL and MariaDB databases

The MySQL and MariaDB NULLIF() function is used to compare two expressions and return NULL if they are equal or the first expression, if they are not equal, which is useful when replacing a certain value with NULL for output or calculations in SQL queries. The function simplifies the logic by allowing comparison and replacement to be performed in a single step, providing flexibility in manipulating and transforming data in SQL queries.

NULLIF() compares the expressions based on their data types and performs a binary comparison. Therefore, the data types of the expressions to be compared should be compatible. The function can be used in applications, such as replacing certain values ​​with NULL, to be able to handle certain conditions or special cases in queries, such as default values ​​or placeholders in result sets as NULL to treat. Furthermore, the function is used to avoid errors in calculations or to simplify conditional expressions.
NAME_CONSTNEXTVALNOWNULLIFNVLNVL2OCT

Further MySQL und MariaDB SQL NULL functions

COALESCECOALESCE(%, %)
More about COALESCE Function

IFNULLIFNULL(Expression, Value)
More about IFNULL Function

ISNULLISNULL(Expression)
More about ISNULL Function

NVLNVL(Expression, Value)
More about NVL Function

NVL2NVL2(Expression, Value1, Value2)
More about NVL2 Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the NULLIF SQL function: mysql.com and mariadb.com and w3schools.com
Updated: 2023-09-24ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer