-
并集:UNION/UNION ALL
union:返回两个集合去掉重复元素后的所有记录 SELECT E.* FROM EMP E,SALGRADE S WHERE S.GRADE = 1 AND E.SAL BETWEEN S.LOSAL AND S.HISAL UNION SELECT E.* FROM EMP E,SALGRADE S WHERE S.GRADE = 2 AND E.SAL BETWEEN S.LOSAL AND S.HISAL;
union all:返回两个集合的所有记录,包括重复的 SELECT E.* FROM EMP E,SALGRADE S WHERE S.GRADE = 1 AND E.SAL BETWEEN S.LOSAL AND S.HISAL UNION ALL SELECT E.* FROM EMP E,SALGRADE S WHERE S.GRADE = 2 AND E.SAL BETWEEN S.LOSAL AND S.HISAL;
-
交集:INTERSECT
intersect:返回同时属于两个集合的记录 SELECT E.* FROM EMP E,SALGRADE S WHERE S.GRADE = 1 AND E.SAL BETWEEN S.LOSAL AND S.HISAL INTERSECT SELECT E.* FROM EMP E,SALGRADE S WHERE S.GRADE = 2 AND E.SAL BETWEEN S.LOSAL AND S.HISAL;
-
差集:MINUX
minux:返回属于第一个集合,但不属于第二个集合的记录 SELECT E.* FROM EMP E,SALGRADE S WHERE S.GRADE = 1 AND E.SAL BETWEEN S.LOSAL AND S.HISAL MINUX SELECT E.* FROM EMP E,SALGRADE S WHERE S.GRADE = 2 AND E.SAL BETWEEN S.LOSAL AND S.HISAL;
-
注意事项
SELECT语句中参数类型和个数要一致
可以使用括号改变集合使用的顺序
如果有 ORDER BY 语句,必须放到最后一句查询语句中
集合运算采用第一个语句的表头作为表头
数据库中的集合运算
最新推荐文章于 2024-04-19 21:00:00 发布