Sep 9, 2019 in Spark Sql

SQL UNION Operator

1 Answer

0 votes
Sep 9, 2019

The SQL UNION Operator

The UNION operator is used to combine the result-set of two or more SELECT statements.

  • Each SELECT statement within UNION must have the same number of columns
  • The columns must also have similar data types
  • The columns in each SELECT statement must also be in the same order

UNION Syntax

SELECT column_name(s) FROM table1
SELECT column_name(s) FROM table2;


The UNION operator selects only distinct values by default. To allow duplicate values, use UNION ALL:

SELECT column_name(s) FROM table1
SELECT column_name(s) FROM table2;

Note: The column names in the result-set are usually equal to the column names in the first SELECT statement in the UNION.

Click here to read more about Loan/Mortgage
Click here to read more about Insurance