T-SQL UNION on 3 tables?

Is it possible? Using SQL Server 2005 .......

SELECT *
FROM Data0304 
UNION 
SELECT *
FROM Data0506
UNION 
SELECT *
FROM Data0708
+5
source share
3 answers

So far, the columns are the same in all three tables, but you can use UNION ALL to provide duplication.

+7
source

When you speak

the columns are the same

which means

number of columns and data types and their length and order

should be the same.

UNION

will include duplicate entries only once as a result and

UNION ALL

will include all duplicate entries.

+4
source

to include duplicate entries you must use UNION ALL instead of UNION

SELECT *
FROM Data0304 
UNION ALL
SELECT *
FROM Data0506
UNION ALL
SELECT *
FROM Data0708
+1
source

All Articles