bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL Tutorial
SQL•SQL Tutorial

SQL UNION Operator

Concept visual

SQL UNION Operator

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

The SQL UNION Operator

The UNION

Formula

operator is used to combine the result - set of two or more

Select

statements.

The UNION

operator automatically removes duplicate rows from the result set.

Requirements for

Union

Every

Select

statement within

Union

must have the same number of columns The columns must also have similar data types

The columns in every

Select

statement must also be in the same order

UNION Syntax

Select

column_name(s)

From

table1

Union Select

column_name(s)

From

table2

;

Note:

Formula

The column names in the result - set are usually equal to the column names in the first

Select

statement.

Demo Database

Below is a selection from the "Customers" table:

CustomerID

CustomerName

ContactName

Address

City

Previous

SQL Self Join

Next

SQL UNION ALL Operator