--union 包括一起--union all 叠加一起select external_number from mall_project_external
unionselect internal_number from mall_project_internal
交集:
mysql数据库取交集,没有对应的关键字,只能把所有要查询的字段都加到where条件上,如下
--语法:--select t1.name, t1.age from t1, t2 where t1.name = t2.name and t1.age = t2.age--如果t1, t2不是表而只是结果集的话,只需要加上with t1 as(...), t2 as (...)就可以了--列如select mall_project_external.external_number from mall_project_external,
mall_project_internal where mall_project_external.external_number = mall_project_internal.internal_number
差集:
mysql数据库取差集,也没有对应的关键字
--1.使用 NOT EXISTS --not exists在比对字段有可利用的索引时,其运行效率是非常高,--但是如果没有索引的情况下运行在大数据表时,其运行效率极差,这时应避免使用它select*from smd_employee t1
whereNOTEXISTS(SELECT1FROM asd_user_account t2
WHERE t2.u_phone = t1.employee_phone)--2.使用 not in-- select name, age from t1
where(t1.name, t1.age)notin(select name, age from t2)