COALESCE function | SQL Tutorial and Query Example

Text copied!

COALESCE function


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

    1. Consider a sequence of values comprising NULL, NULL, 1, and 2.

    COALESCE(expression1, expression2, expression3, ...)
    To enhance your understanding of 'SQL functions', be sure to check out our next tutorial.
    SELECT COALESCE(NULL, NULL, 1, 2) AS Result;
            
    COALESCE function

    Frequently Asked Questions :

    COALESCE in SQL returns the first non-null value among its arguments.
    To coalesce two columns in SQL, you use the COALESCE function with those columns as arguments.
    The difference between COALESCE() and ISNULL() in SQL is that COALESCE() can take multiple parameters and returns the first non-null value, while ISNULL() is specific to SQL Server and only replaces null values with a specified replacement.
    NULLIF in SQL returns null if the two specified expressions are equal, while COALESCE returns the first non-null expression among its arguments.