NULLIF function | SQL Tutorial and Query Example

Text copied!

NULLIF function


  • The syntax of the NULLIF function generally looks like this :
    Here's an example of how you might use the NULLIF function :

    1. Let's assume we have a table named "[Employees]".

    NULLIF(expression1, expression2)
    Remember :

    Using this function in a select statement won't modify the [Employees] table directly, but it will only be reflected in the select statement's output.

    To enhance your understanding of 'SQL functions', be sure to check out our next tutorial.
    NULLIF function
    SELECT *, NULLIF(Gender, 'Female') AS [Gender2]
    FROM [Employees];
            
    NULLIF function

    Frequently Asked Questions :

    Nullif function in SQL returns NULL if two expressions are equal, otherwise, returns the first expression.
    Nullif value in SQL is the value to be compared with another expression to determine if it should return NULL.
    The difference between NULL and Nullif in SQL is that NULL represents the absence of a value, while Nullif compares two expressions and returns NULL if they are equal.
    Nullif and coalesce are SQL functions used for handling NULL values; Nullif compares two expressions and returns NULL if they are equal, while coalesce returns the first non-NULL expression from a list.