union 和 union all的区别

相同点和不同点

相同点:
union和union all 都是对于多个查询结果的并集进行操作
不同点:
1.union 不会输出两个结果并集的重复行
2.union all 会输出两个结果并集的重复行

实验表

字段解释:
xh:学号
xh:姓名
nl:年龄

create table student(xh number,xm varchar2(4),nl int);
insert into student values(1,'A',21);
insert into student values(2,'B',21);
insert into student values(3,'A',21);
insert into student values(4,'A',21);
insert into student values(5,'A',21);
insert into student values(6,'C',21);
insert into student values(7,'B',21);

查看表

SQL> select * from student;

    XH XM           NL
---------- ------------ ----------
1 A 21
2 B 21
3 A 21
4 A 21
5 A 21
6 C 21
7 B 21 7 rows selected. SQL>

例子

union

SQL> select * from student
2 union
3 select * from student where xm='A'; XH XM NL
---------- ------------ ----------
1 A 21
2 B 21
3 A 21
4 A 21
5 A 21
6 C 21
7 B 21 7 rows selected.

union all

SQL> select * from student
2 union all
3 select * from student where xm='A'; XH XM NL
---------- ------------ ----------
1 A 21
2 B 21
3 A 21
4 A 21
5 A 21
6 C 21
7 B 21
1 A 21
3 A 21
4 A 21
5 A 21 11 rows selected. SQL>

  

union 和 union all的区别的更多相关文章

  1. Union和Union All到底有什么区别

    以前一直不知道Union和Union All到底有什么区别,今天来好好的研究一下,网上查到的结果是下面这个样子,可是还是不是很理解,下面将自己亲自验证: Union:对两个结果集进行并集操作,不包括重 ...

  2. union和union all的区别

    UNION 写一篇联合查询(把前后两个表的查询结果集合在前表中)首先有个为什么需要 相同记录数?? 记错了.应该是union两张表的查询字段数目要一致,字段类型要相似相同的数据类型,至少是相似,可转化 ...

  3. Oracle之Union与Union all的区别

    如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字.union(或称为联合)的作用是将多个结果合并在一起显示出来. union和unio ...

  4. union与union all的区别

    首先说下union与join的区别 1.union是以行增加的方式,进行连接:join是以列增加的方式进行连接: 2.union连接查询的两个表的字段必须要一一对应,数目相等:join则没有要求,但是 ...

  5. C和C++中结构体(struct)、联合体(union)、枚举(enum)的区别

    C++对C语言的结构.联合.枚举 这3种数据类型进行了扩展. 1.C++定义的结构名.联合名.枚举名 都是 类型名,可以直接用于变量的声明或定义.即在C++中定义变量时不必在结构名.联合名.枚举名 前 ...

  6. Ms SQLServer中的Union和Union All的使用方法和区别

    Ms SQLServer中的Union和Union All的使用方法和区别 SQL UNION 操作符 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的 ...

  7. union与union all 的区别

    Union与Union All的区别 如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字.union(或称为联合)的作用是将多个结果合并 ...

  8. Union 与 Union all 区别

    原创,请园长不要删 Sql查询统计时,很多时候用到了union 和 union all,union与union all的区别就是联合查询的时候union会去重,union all不会去重.本人用uni ...

  9. SQL Server函数​---Union与Union All的区别

    SQL Server函数---Union与Union All的区别 如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字.union(或称 ...

  10. Oracle中Union与Union All的区别(适用多个数据库)

    Oracle中Union与Union All的区别(适用多个数据库) 如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字.union(或 ...

随机推荐

  1. springboot自动装配redis在pool下偶尔出现连接异常的问题

    jedis pool的配置其实是采用 org.apache.commons.pool2.impl.GenericObjectPoolConfig类的配置项. jedis 2.9版本代码如下: pack ...

  2. 超线程技术(Hyper—Threading Technology,HTT)

    什么是超线程技术 超线程技术就是利用特殊的硬件指令,把两个逻辑内核模拟成两个物理芯片,让单个处理器都能使用线程级并行计算.具体讲,就是通过CPU的寄存器构成了两个逻辑处理器,来共享处理器的物理执行单元 ...

  3. 009-MySQL循环while、repeat、loop使用

    一.循环使用 mysql常见的三种循环方式:while.repeat和loop循环.还有一种goto,不推荐使用. 前提1.创建基本表结构 # 创建表结构 drop table if exists ` ...

  4. 使用response将html拼接页面写到当前浏览器端完成自动提交功能

    /** * 准备中间页面所需参数 * add by linyan  2014-9-22 * @param url * @param params * @param charset * @return ...

  5. python读取yaml文件,在unittest中使用

    python读取yaml文件使用,有两种方式: 1.使用ddt读取 2,使用方法读取ddt的内容,在使用方法中进行调用 1.使用ddt读取 @ddt.ddt class loginTestPage(u ...

  6. WebViewJavascriptBridge js跟app的交互框架

    https://github.com/marcuswestin/WebViewJavascriptBridge 参考: https://www.cnblogs.com/LiLihongqiang/p/ ...

  7. [LeetCode] 131. Palindrome Partitioning 回文分割

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  8. kexue shangwang

    根据实践,pptp.IPsec甚至OpenVPN等kexue上网法已经无法顺利翻越GFW.通过抓包可知,GFW会将pptp的握手期间的ack包吞掉,导致本地一直无法收到服务器端的响应.而OpenVPN ...

  9. 使用consul实现分布式服务注册和发现--redis篇

    安装consul client consul 客户端检脚本 ====================================================================== ...

  10. 配置tomcat 加载指定的jar

    # vi bin/catalina.sh