Oracle
集合运算
基本上可以用下图表示
Oracle
的几种集合运算,黄色表示结果集:
联合(
Union
)案例:
select
1
,
2
from dual union select
2
,
3
from dual
|
完全联合(
Union All
)案例:
select
1
,
2
from dual unionall select
1
,
2
from dual
|
相交
(Intersect)
案例:
select
* from ( select
1
,
2
from dual unionall select
3
,
3
from dual )
intersect
select
3
,
3
from dual
|
相减
(minus)
案例:
select
a,b from ( select
1
as a,
2
as b from dual unionall select
3
as a,
3
as b from dual )
MINUS
select
3
as a,
3
as b from dual
|
Union
排序只能放在最后
COLUMN
a_dummy NOPRINT SELECT
'sing'
AS "My dream",
3
a
_dummy FROM dual UNION SELECT
'I''d like to teach'
,
1
FROM dual UNION SELECT
'the world to'
,
2
FROM dual ORDERBY
2
;
|