开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜