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下载
时间: 2024-10-13 12:37:15