UNION / UNION ALL 区别

Posted thought

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UNION / UNION ALL 区别相关的知识,希望对你有一定的参考价值。

Union:对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序;

Union All:对两个结果集进行并集操作,包括重复行,不进行排序;

使用union all:

select top 5 OrderID,[EmployeeID] from dbo.Orders where EmployeeID=1
union all
select top 5 OrderID,[ProductID] from [Order Details] where ProductID=1

  

 

 

使用union:

select top 5 OrderID,[EmployeeID] from dbo.Orders where EmployeeID=1
union
select top 5 OrderID,[ProductID] from [Order Details] where ProductID=1

  

 

附下微软示例数据库连接:NORTHWIND下载

 

以上是关于UNION / UNION ALL 区别的主要内容,如果未能解决你的问题,请参考以下文章

Union和Union All到底有什么区别

Union和Union All到底有什么区别

Union和Union All到底有什么区别

union和union all的区别

union all和union的区别 怎么使用

union和union all的区别