SQL UNION Operator
SQL UNION Operator
SQL
1. SQL COMMANDS
COMMANDS FOR
FOR BEGINNERS
BEGINNERS
2. FULL
2. FULL JOIN
JOIN IN
IN SQL
SQL
SQL UNION
Operator
‹ Previous Next ›
UNION Syntax
Demo Database
In this tutorial we will use the well-known
Northwind sample database.
Search for
SQL Tutorial
Example Get your own SQL Server
SQL HOME
SQL Intro SELECT City FROM Customers
SQL Syntax UNION
SQL Select SELECT City FROM Suppliers
SQL Select Distinct ORDER BY City;
SQL Where
SQL Order By Try it Yourself »
SQL And
SQL Or
SQL Not Note: If some customers or suppliers have the
SQL Insert Into same city, each city will only be listed once,
SQL Null Values because UNION selects only distinct values. Use
SQL Update UNION ALL to also select duplicate values!
SQL Delete
SQL Select Top
SQL Aggregate Functions SQL UNION ALL Example
SQL Min and Max
SQL Count The following SQL statement returns the cities
SQL Sum (duplicate values also) from both the "Customers"
SQL Avg and the "Suppliers" table:
SQL Like
SQL Wildcards
SQL In Example
SQL Between SELECT City FROM Customers
SQL Aliases UNION ALL
SQL Joins SELECT City FROM Suppliers
SQL Inner Join ORDER BY City;
SQL Left Join
SQL Right Join Try it Yourself »
SQL Full Join
SQL Self Join
SQL Union
SQL Group By
SQL Having SQL UNION With WHERE
SQL Exists
The following SQL statement returns the German
SQL Any, All
cities (only distinct values) from both the
SQL Select Into
"Customers" and the "Suppliers" table:
SQL Insert Into Select
SQL Case
SQL Null Functions
Example
SQL Stored Procedures
SQL Comments
SELECT City, Country FROM Customers
SQL Operators WHERE Country='Germany'
UNION
SQL Database SELECT City, Country FROM Suppliers
SQL Create DB WHERE Country='Germany'
ORDER BY City;
SQL Drop DB
SQL Drop DB
SQL Backup DB
SQL Create Table Try it Yourself »
SQL Drop Table
SQL Alter Table
SQL Constraints
SQL Not Null
SQL Unique
SQL UNION ALL With
SQL Primary Key
SQL Foreign Key
WHERE
SQL Check The following SQL statement returns the German
SQL Default cities (duplicate values also) from both the
SQL Index "Customers" and the "Suppliers" table:
SQL Auto Increment
SQL Dates
SQL Views Example
SQL Injection
SQL Hosting SELECT City, Country FROM Customers
SQL Data Types WHERE Country='Germany'
UNION ALL
SELECT City, Country FROM Suppliers
SQL References
SQL Keywords WHERE Country='Germany'
MySQL Functions ORDER BY City;
SQL Server Functions
MS Access Functions Try it Yourself »
SQL Quick Ref
SQL Examples
SQL Examples
SQL Editor
Another UNION Example
SQL Quiz
The following SQL statement lists all customers
SQL Exercises
and suppliers:
SQL Server
SQL Bootcamp
SQL Certificate
Example