SQL关键字 union、intersect、except用法

1.union是A集合和B集合的并集;

select 'S_E_Product' FormType,Name,Code,Version,ProjectInfoID,WBSID,MajorValue from  S_E_Product where ID='ac130126-8cf2-48e5-8584-f1c737dd3678'
union
select 'S_E_ProductVersion' FormType,Name,Code,Version,ProjectInfoID,WBSID,MajorValue from  S_E_ProductVersion where 
ProductID='ac130126-8cf2-48e5-8584-f1c737dd3678'

2.intersect是A集合和B集合的交集;

select Name,Code,Version,ProjectInfoID,WBSID,MajorValue from  S_E_Product where ID='ac130126-8cf2-48e5-8584-f1c737dd3678'

intersect

select Name,Code,Version,ProjectInfoID,WBSID,MajorValue from  S_E_ProductVersion where 
ProductID='ac130126-8cf2-48e5-8584-f1c737dd3678'

3.except是A集合减去B集合的结果;

select Name,Code,Version,ProjectInfoID,WBSID,MajorValue from  S_E_ProductVersion where 
ProductID='ac130126-8cf2-48e5-8584-f1c737dd3678'
except
select Name,Code,Version,ProjectInfoID,WBSID,MajorValue from  S_E_Product where ID='ac130126-8cf2-48e5-8584-f1c737dd3678'

注:都是返回的是非重复值,联合查询的表字段必须一致。

 


版权声明:本文为m0_45474448原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。