Oracle_071_lesson_p9

集合操作

Oracle_071_lesson_p9
UNION 及 UNION ALL
UNION :列名,數據類型要一致,結果會默認ASC自動排序
UNION ALL :結果不會去重,不排序,其他和UNION一樣
用類似to_char(null), to_number(null), to_date(null) 來填充缺列的情況;
如:
select job_id
from employees
UNION
select job_id
from retired_employees

如:
select job_id,department_id
from employees
UNION ALL
select job_id,department_id
from retired_employees
order by job_id;

intersect 取交集
結果會排序,會去重
如:
select manager_id,department_id
from employees
INTERSECT
select manager_id,department_id
from retired_employees;

MINUS 前select的結果減去和後select的去重複的結果
如:
select employee_id, job_id
from employees
where department_id=80
MINUS
select employee_id, job_id
from retired_employees
where department_id=90

以上4種輸出結果都只關心第1條select的定義
order by 只能放在最後,且只能出現1次,且不能放在子查詢裏。
parenthes 括號可以更改執行優先級。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章