【mysql】union

190 阅读1分钟

union

把多个select 语句的结果组合到一个结果集合中

1.1 union 与 union all 的区别

用union 时,mysql 会把结果集中重复的记录删掉
而用union all ,mysql 会把所有的记录返回,且效率高于union 。

select 字段 from 表 where 条件 
union
select 字段 from 表 where 条件 ;

or中

image.png

and中

image.png image.png

顺序

先返回null的所有值,再返回数字 image.png

image.png