资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

union和unionall的区别

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.

SQL> 

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和unionall的区别
文章起源:http://cdkjz.cn/article/ighjgc.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220