UNION operator | SQL Tutorial and Query Example

Text copied!

UNION operator


  • UNION operator :

    UNION operator is used to merge the result of multiple SELECT statements into a single result by eliminating duplicate rows.

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

    Let's suppose we have two tables :

    To enhance your understanding of 'SQL operators', be sure to check out our next tutorial.
    SELECT column_name(s)
    FROM table1
    UNION
    SELECT column_name(s)
    FROM table2;
            
    UNION operator
    SELECT *
    FROM [Employees]
    UNION
    SELECT *
    FROM [Employees_2];
            
    UNION operator
    SELECT Employee_Id, Employee_Name, Gender, Salary
    FROM [Employees]
    UNION
    SELECT Employee_Id, Employee_Name, Gender, Salary
    FROM [Employees_2];
            
    UNION operator

    Frequently Asked Questions :

    JOIN combines rows from two or more tables based on a related column, while UNION combines the result sets of two or more SELECT statements into a single result set.
    Yes, by default, UNION removes duplicates from the combined result set.
    Use the UNION operator to merge the results of two queries into a single result set.
    The UNION set operator in SQL merges the results of two or more SELECT queries into a single result set while removing duplicate rows.