UNION ALL clause | SQL Tutorial and Query Example

Text copied!

UNION ALL clause


  • UNION ALL clause :

    UNION ALL clause is used to combine/merge the result of multiple SELECT statements into a single result by keeping duplicate rows.

    The syntax of the UNION ALL clause generally looks like this :
    Here's an example of how you might use the UNION ALL clause :

    Let's suppose we have two tables :

    SELECT column_name(s)
    FROM table1
    UNION ALL
    SELECT column_name(s)
    FROM table2;
            
    UNION ALL clause
    SELECT *
    FROM [Employees]
    UNION ALL
    SELECT *
    FROM [Employees_2];
            
    UNION ALL clause
    SELECT Employee_Id, Employee_Name, Gender, Salary
    FROM [Employees]
    UNION ALL
    SELECT Employee_Id, Employee_Name, Gender, Salary
    FROM [Employees_2];
            
    UNION ALL clause

    Frequently Asked Questions :

    The UNION ALL clause in SQL combines the results of two or more SELECT statements, including duplicate rows.
    Using UNION ALL in SQL can be beneficial for combining results from multiple queries if you need to include duplicate rows.
    Yes, you can use the WHERE clause in a UNION query to filter the results based on specified conditions.
    No, UNION ALL does not remove duplicates; it includes all rows from the combined result sets, even if there are duplicates.