SQL UNION






The SQL UNION is used to combine the results of two or more SELECT SQL statements into a single result. All the statements concatenated with UNION must have the same structure. This means that they need to have the same number of columns, and corresponding columns must have the same or compatible data types (implicitly convertible to the same type or explicitly converted to the same type). The columns in each SELECT statement must be in exactly the same order too.

This is how a simple UNION statement looks like:

SELECT Column1, Column2 FROM Table1
UNION
SELECT Column1, Column2 FROM Table2

The column names in the result of a UNION are always the same as the column names in the first SELECT statement in the UNION.

The UNION operator removes by default duplicate rows from the result set. You have the option to use the ALL keyword after the UNION keyword, which will force all rows including duplicates to be returned in your result set.




SQL Tutorial

SQL Tutorial
SQL Introduction
RDBMS and Tables
SQL SELECT
SQL WHERE
SQL INSERT
SQL DISTINCT
SQL UPDATE
SQL DELETE
SQL ORDER BY
SQL Aggregate Functions
SQL GROUP BY
SQL HAVING
Relations, Keys, and Normalization
SQL JOIN
SQL UNION
SQL Nested Queries
CREATE DATABASE, CREATE TABLE and ALTER TABLE
SQL Views
SQL Indexes
SQL Training
SQL Hosting
SQL Replication
Contact Us
Legal
SQL Resources
Copyright © Art Branch Inc
SQL Tutorial | Bookmark | Contact | Link