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'
注:都是返回的是非重复值,联合查询的表字段必须一致。
本文介绍了SQL中的三种集合操作:UNION用于获取两个查询结果的并集,INTERSECT用于获取两个查询结果的交集,而EXCEPT则用于获取第一个查询结果中不在第二个查询结果中的记录。示例展示了如何在S_E_Product和S_E_ProductVersion表中使用这些操作进行数据查询。
180

被折叠的 条评论
为什么被折叠?



