SQLforGeeks
  • Home
  • SQL
  • SQL Tutorial
  • SQL Syntax
  • Our Services
Contact
  1. SQL
  2. COALESCE function

Text copied!

« Previous
Next »

COALESCE function

June 20, 2023, 7:17 p.m. under SQL

  • Hi! You should check NULLIF function post first.

    In SQL, the COALESCE function is used to return the first non-null expression/value in a list of expressions/values.

    The syntax of the COALESCE function generally looks like this :
    COALESCE(expression1, expression2, expression3, ...)

    • Define the 'expression1', 'expression2', 'expression3' and so on.

    Here's an example of how you might use the COALESCE function :

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

    2. Run below SQL statement :

    SELECT COALESCE(NULL, NULL, 1, 2) AS Result;
            

    3. In this example, the query successfully retrieves the first non-null value which is number '1' from the series of inputs given to COALESCE.

    COALESCE function
    To enhance your understanding of 'SQL functions', be sure to check out our next tutorial.

    Frequently Asked Questions :

    What is the function of coalesce in SQL?

    COALESCE in SQL returns the first non-null value among its arguments.

    How do I coalesce two columns in SQL?

    To coalesce two columns in SQL, you use the COALESCE function with those columns as arguments.

    What are the differences between coalesce () and Isnull () in SQL?

    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.

    What is nullif and coalesce in SQL?

    NULLIF in SQL returns null if the two specified expressions are equal, while COALESCE returns the first non-null expression among its arguments.
    Thank You! You should check SQL Window functions post next.
    « Previous
    Next »
    RELATED :

    What is SQL

    What is T-SQL

    Difference between DBMS and Data Warehouse

    Download SQL Server

    Install SQL Server

    Download SQL Server Management Studio SSMS

    SQL Server Management Studio

    SQL Database

    Download database

    Restore database

    Backup database

    Attach database

    Detach database

    Create database

    Delete database

    Rename database

    Select database

    Database offline

    Database online

    SQL Commands

    SQL Tables

    Create table

    Truncate table

    Delete table

    Rename table

    Select table

    Alter table

    SQL Data Types

    SQL Comments

    SQL Constraints

    SQL Joins

    SQL inner join

    SQL left join

    SQL right join

    SQL full join

    SQL cross join

    SQL self join

    INSERT INTO SELECT statement

    INSERT INTO statement

    SQL Clauses

    SELECT clause

    FROM clause

    WHERE clause

    GROUP BY clause

    HAVING clause

    ORDER BY clause

    JOIN clause

    UNION clause

    UNION ALL clause

    TOP clause

    DISTINCT clause

    SQL Operators

    SQL Arithmetic operators

    SQL Comparison operators

    SQL Logical operators

    UNION operator

    UNION ALL operator

    INTERSECT operator

    EXCEPT operator

    LIKE operator

    NOT LIKE operator

    IN operator

    NOT IN operator

    IS NULL operator

    IS NOT NULL operator

    EXISTS operator

    NOT EXISTS operator

    BETWEEN operator

    NOT BETWEEN operator

    SQL Functions

    SQL Built-In functions

    CHARINDEX function

    DATEADD function

    CONCAT function

    LEN function

    REPLACE function

    SUBSTRING function

    CASE statement

    GETDATE function

    DATEPART function

    DATEDIFF function

    CAST function

    TRY_CAST function

    CONVERT function

    TRY_CONVERT function

    ISNULL function

    NULLIF function

    SQL Window functions

    ROW_NUMBER function

    RANK function

    DENSE_RANK function

    IIF function

    CHOOSE function

    SQL Store Procedure

    Store Procedure vs. Function

    SQL Subquery

    SQL Aliases

    Temp table

    SQL Error Handling

    SQL Variables

    SQL Views

    SQL Merge

    SQL CTE

    SQL WITH TIES

    Define Transaction in DBMS

    ACID properties in DBMS

    Types of Triggers in DBMS


    • Have Some Questions?
    logo

    Elevate your data experience with SQL excellence

    Quick Links
    •  Home
    •  SQL Tutorial
    •  SQL Syntax
    •  Our Services
    Our Services
    • Web Development
    • BI Development
    • Data Warehousing
    • Data Integration ETL


    Follow Us

    GST Registered: XXAXXXXXXXZX
    Mumbai, Maharashtra, India support@sqlforgeeks.com

    © 2025 Copyright™ | All Rights Reserved | Privacy Policy