union 对前后两个结果集进行合并,去掉重复的数据,按默认规则对结果集进行排序
union all 对前后两个结果集进行合并,保留重复的数据,不会进行排序
注:前后两个结果集的字段是一致的,否则无法使用union或union all。
例如对表t1和表t2进行union(all)操作:
![](https://img.haomeiwen.com/i21813804/c575dbfe0045e648.png)
union操作:
![](https://img.haomeiwen.com/i21813804/eb1dd3c88d0c79fd.png)
union all 操作:
![](https://img.haomeiwen.com/i21813804/71fe0af9f4fa5f01.png)
union 对前后两个结果集进行合并,去掉重复的数据,按默认规则对结果集进行排序
union all 对前后两个结果集进行合并,保留重复的数据,不会进行排序
注:前后两个结果集的字段是一致的,否则无法使用union或union all。
例如对表t1和表t2进行union(all)操作:
union操作:
union all 操作:
本文标题:MySQL中union和union all的使用
本文链接:https://www.haomeiwen.com/subject/ifwevhtx.html
网友评论