oracle 四种集合运算
2014-06-02 11:44
786 查看
oracle 支持4种集合运算符: union , union all , minus , intersect
union 返回来自所有输入查询的不包含重复值的结果集。
union all 返回两个集合中的所有行,包含重复。
minus 将第一个查询的结果集作为基础数据集减去另一个查询结果集。 通常代替not exists (反联结)
意思是:我需要返回在数据行源A中存在但是在B中不存在的数据行集。
intersect 返回在所有输入查询中都存在的唯一行集。通常代替exists(半联结)
意思是:我需要返回源A和B中都存在的数据行集合
union 返回来自所有输入查询的不包含重复值的结果集。
union all 返回两个集合中的所有行,包含重复。
minus 将第一个查询的结果集作为基础数据集减去另一个查询结果集。 通常代替not exists (反联结)
意思是:我需要返回在数据行源A中存在但是在B中不存在的数据行集。
intersect 返回在所有输入查询中都存在的唯一行集。通常代替exists(半联结)
意思是:我需要返回源A和B中都存在的数据行集合
</pre><pre name="code" class="plain">SQL> select color from table1; 测试表1 COLOR ---------- RED RED ORANGE ORANGE ORANGE YELLOW GREEN BLUE BLUE VIOLET 10 rows selected. SQL> select color from table2; 测试表2 COLOR ---------- RED RED BLUE BLUE BLUE GREEN 6 rows selected. SQL> select color from table3; 测试表3 SQL> select color from table1 union union 去除重复行 2 union 3 select color from table2; COLOR ---------- BLUE GREEN ORANGE RED VIOLET YELLOW 6 rows selected. SQL> select color from table1 union all 不会去除重复行 2 union all 3 select color from table2; COLOR ---------- RED RED ORANGE ORANGE ORANGE YELLOW GREEN BLUE BLUE VIOLET RED RED BLUE BLUE BLUE GREEN 16 rows selected. SQL> select color from table1 union 与空表进行集合运算 2 union 3 select color from table3 4 ; COLOR ---------- BLUE GREEN ORANGE RED VIOLET YELLOW 6 rows selected. SQL> select color from table1 table1 减去table2 2 minus 3 select color from table2; COLOR ---------- ORANGE VIOLET YELLOW SQL> select color from table2 2 minus 3 select color from table1; no rows selected SQL> select color from table1 table1和table2都存在的行 2 intersect 3 select color from table2; COLOR ---------- BLUE GREEN RED
相关文章推荐
- oracle多表联合查询,统计查询,组函数,order by,having,子查询,集合运算
- oracle多表联合查询,统计查询,组函数,order by,having,子查询,集合运算
- Oracle备忘录(六)--集合运算和子查询
- oracle 集合运算
- 5.创建表,使用alter进行表信息的增删改,Oracle回收站,集合运算
- Oracle 四种结果集集合操作命令 Union、Union All、Intersect、Minus
- oracle 多表联合查询,统计查询,组函数,order by,having,子查询,集合运算,
- Oracle基础知识(十九) - 集合运算
- Oracle集合运算
- 【Java EE 学习 28 上】【oracle学习第二天】【子查询】【集合运算】【几种数据库对象】
- oracle 多表联合查询,统计查询,组函数,order by,having,子查询,集合运算
- Oracle 四种结果集集合操作命令 Union、Union All、Intersect、Minus
- Oracle 集合运算
- oracle集合运算_10级 学员 马林 课堂总结
- Oracle学习(七):集合运算
- Oracle 四种结果集集合操作命令 Union、Union All、Intersect、Minus
- Oracle(八)--------------------集合运算
- Oracle集合运算
- oracle多表联合查询,统计查询,组函数,order by,having,子查询,集合运算
- Oracle学习(七):集合运算