Other related articles:

Recently viewed articles:

NULLIF (SQL)

NULLIF SQL function is used to compare two expressions which are passed as arguments to this function. If both expression are equal this function will return NULL values, otherwise it will return first expression as a result. The syntax  is:

NULLIF (expr1, expr2);

NULLIF SQL Function is logically equivalent to following IF statement:

IF expr1 = expr2 THEN
NULL;
ELSE
expr1;
ENDIF;

Example:

The following example uses NULLIF SQL Function to compare first_name and last_name of employees in employee table and return NULL if both are same:

SELECT full_name, NULLIF ( first_name, last_name) FROM employee;

Output:
nullif sql image1