Monday, January 3, 2011

SQL UNION

The UNION operator is used to combine the result-set of two or more SELECT statements.
Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.

syntax 1.

SELECT column_name(s) FROM table_name1
UNION
SELECT column_name(s) FROM table_name2


syntax 2.

SELECT column_name(s) FROM table_name1
UNION ALL
SELECT column_name(s) FROM table_name2

No comments:

Post a Comment