集合操作
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 括號可以更改執行優先級。