数据库之集合查询

集合查询

一、并查询(union)

    格式:
select ...........
from 表1 left join 表2
on........
union
select ...........
from 表2 right join 表2
on........
    作用:
求两个select的并集,去掉重复项
    注意:
两个表的字段数和数据类型相同
二、交查询(intersect)
    格式
(select ...........
from .......
where........)
intersect
(select ...........
from........
where........)
    作用:
求两个select的交集
    注意:
两个表的字段数和数据类型相同,mysql不支持
三、差查询(minus/except) 
格式1(oracle):
select ...........
from .......
where........
minus
select ...........
from........
where........
格式2(sql server):
select ...........
from .......
where........
except
select ...........
from........
where........
    作用:
找出满足第一个select并不满足第二个select的数据
    注意:
两个表的字段数和数据类型相同,mysql不支持
原文地址:https://www.cnblogs.com/SoulReaper/p/3309800.html