set运算符:在select列表中两个表查询的列数量和数据类型要相对应
set运算符包括union操作符、union all操作符、intersect操作符、minus操作符
union操作符:返回两个查询的结果集的并集,去掉结果集的重复部分
select last_name,salary
from employees
where department_id=30
union
select last_name,salary
from emp10
where department_id in (30,100);
图示1.1:
Union all操作符:返回两个查询的结果集的并集,不去除两个结果集的重复部分
select last_name,salary
from employees
where department_id=30
union all
select last_name,salary
from emp10
where department_id in (30,100);
图示1.2:
Intersect操作符:返回两个结果集的交集
select last_name,salary
from employees
where department_id=30
intersect
select last_name,salary
from emp10
where department_id in (30,100);
图示1.3:
Minus操作符:返回两个结果集的差集,减去它们的交集部分
select last_name,salary
from emp10
where department_id in (30,100)
minus
select last_name,salary
from employees
where department_id=30;
图示1.4:
相对位置排序:
Select ‘wonderful’,1
From dual
Union
Select ‘I hope’,2
From dual
Union
Select ‘the world to be’,3
From dual
Order by 1;
图示1.5: