MySQL 查询语句--------------进阶9:联合查询
#进阶9:联合查询 /* union 联合 合并:将多条查询语句的结果合并成一个结果 语法: 查询语句1 union 查询语句2 union..... 应用场景:要查询的结果来自于多个表,且多个表没有直接的连接关系,但查询的信息一致时 特点: (1)要求多条查询语句的查询列数是一致的 (2)要求多条查询语句的查询的每一列的类型和顺序最好一致 (3)union去重,union all不去重 */ #引入的案例:查询部门编号>90或者邮箱包含a的员工信息 select * from employees where department_id>90 or email like "%a%"; 用union select * from employees where department_id>90 union select * from employees where email like "%a%"; 经典面试题:union 与 union all的区别 union会对结果集进行处理,排除掉相同的结果 union all 不会对结果集进行处理,不会处理掉相同的结果

浙公网安备 33010602011771号