Union,对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序;
Union All,对两个结果集进行并集操作,包括重复行,不进行排序;
我们来看一下例子:
(1)这是Union
SQL> select *
2 from student
3 where id<4
4 union
5 select *
6 from student
7 where id>2 and id<6
8 ;
ID NAME SCORE
---------- ------------------------------ ----------
1 Aaron 78
2 Bill 76
3 Cindy 89
4 Damon 90
5 Ella 73
(2)这是Union All
SQL> select *
2 from student
3 where id<4
4 union all
5 select *
6 from student
7 where id>2 and id<6
8 ;
ID NAME SCORE
---------- ------------------------------ ----------
1 Aaron 78
2 Bill 76
3 Cindy 89
3 Cindy 89
4 Damon 90
5 Ella 73
6 rows selected.
通过这个例子应该明白了吧! |