UNION 用于合并两个或多个 SELECT 语句的结果集,并消去表中任何重复行。
student 表:
1、使用union
SELECT * FROM student where id < 5
UNION
SELECT * from student where id >3 and id<8
查询结果
2、使用union all
select * from student where id < 5
union all
select * from student where id >3 and id <8
查询结果
通过测试可发现
union 对两个结果集进行并集操作,重复数据只显示一次
Union All,对两个结果集进行并集操作,重复数据全部显示