温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

union 和 union all的区别

发布时间:2020-08-16 05:58:45 来源:网络 阅读:2112 作者:运维少年 栏目:关系型数据库

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> 
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI