您好,登錄后才能下訂單哦!
相同點:
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>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。