T-SQL UNION On 3 Tables?
Is this possible? Using SQL Server 2005.......
开发者_高级运维SELECT *
FROM Data0304
UNION
SELECT *
FROM Data0506
UNION
SELECT *
FROM Data0708
As long as the columns are the same in all three tables, but you might want to use UNION ALL to ensure duplicates are included.
When you say
columns are same
that means,
number of columns and data types and their lengths and their order
should be same.
UNION
will include duplicate records only once in the result and
UNION ALL
will include all the duplicate records.
in order to include duplicate records you have to use UNION ALL instead of UNION
SELECT *
FROM Data0304
UNION ALL
SELECT *
FROM Data0506
UNION ALL
SELECT *
FROM Data0708
精彩评论