SQL UNION Operator Tutorial With Example | Union Clause in SQL is today’s topic. SQL UNION operator is used to combine a result sets of 2 or more SELECT statements. It removes the duplicate rows between the several SELECT statements.
What is the use of Union Operator
A UNION operator is used to combine a result-set of two or more SELECT statements.
- Each SELECT statement within a UNION must have the same number of columns selected.
- It should have the same number of columns expressions and same datatypes written with the same order.
- The columns in each SELECT statement should also be in the same order.
- The result set obtained by Union clause excluding the duplicate rows between the various results set.
In this article, we’ll review:
- UNION and UNION all and how they work.
- We discuss the rules for using UNION vs. UNION ALL.
- SQL Operator Syntax.
- How to use the simple SQL UNION clause in the select statement.
- How to use the SQL UNION with the queries that have a WHERE clause.
#sql #sql union