1.集合
集合:每一个sql查询的结果就是一个集合
(1,3,4,65,234,123,12)
并集:取两个集合中所有元素
union all:表示取两个集合的并集,不删除重复元素
union:取两个集合的并集,删除重复的元素
–查询员工工资大于1000的员工信息
select * from emp where sal>1000;
–查询员工工资小于3000的员工信息
select * from emp where sal<3000;
–查询员工工资大于1000 和 小于3000 的员工信息(每个人员出现一次)
select * from emp where sal>1000
union all
select * from emp where sal<3000;
–查询员工工资大于1000 和 小于3000 的员工信息(每个人员会出现多次)
select * from emp where sal>1000
union
select * from emp where sal<3000;
union、union all:union all执行效率高,union执行效率低(先进行union all把两个集合合并,之后对合并后的数据进行排序,去掉重复元素)
交集:取两个集合重叠部分的元素
intersect:表示交集
–查询工资在1000到3000之间的员工信息
select * from emp where sal>1000 and sal<3000;
select * from emp where sal>1000
intersect
select