开发者

T-SQL UNION On 3 Tables?

开发者 https://www.devze.com 2022-12-21 11:48 出处:网络
Is this possible? Using SQL Server 2005.......开发者_高级运维 SELECT * FROM Data0304 UNION SELECT *

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

精彩评论

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

关注公众号