当前位置:网站首页>mysql中union和union all的区别
mysql中union和union all的区别
2022-06-30 18:06:00 【日光咖啡】
一、区别1:取结果的交集
1、union: 对两个结果集进行并集操作, 不包括重复行,相当于distinct, 同时进行默认规则的排序;
2、union all: 对两个结果集进行并集操作, 包括重复行, 即所有的结果全部显示, 不管是不是重复;
二、区别2:获取结果后的操作
1、union: 会对获取的结果进行排序操作
2、union all: 不会对获取的结果进行排序操作
三、区别3:
1、union看到结果中ID=3的只有一条
select * from student2 where id < 4
union
select * from student2 where id > 2 and id < 6
2、union all 结果中ID=3的结果有两个
select * from student2 where id < 4
union all
select * from student2 where id > 2 and id < 6
四、总结
union all只是合并查询结果,并不会进行去重和排序操作,在没有去重的前提下,使用union all的执行效率要比union高
原文链接:https://blog.csdn.net/a200822146085/article/details/119545374
边栏推荐
- Memory Limit Exceeded
- 「干货」数据分析常用的10种统计学方法,附上重点应用场景
- MySQL recursion
- The cloud native landing practice of using rainbow for Tuowei information
- mysql函数获取全路径
- torch stack() meshgrid()
- Electron 入门
- Swin-Transformer(2021-08)
- 基于UDP协议设计的大文件传输软件
- Compare the audio librosa library with the Mel spectrogram in the torchaudio library
猜你喜欢

Year after year, why is breaking the data island still the primary task of enterprise development

Browser window switch activation event visibilitychange

VMware16安装Win11虚拟机(最全步骤+踩坑)

详解单例模式

PC wechat multi open

Electron 入门

20220607 fell below the recommended retail price, and the GPU market is moving towards oversupply

Video content production and consumption innovation

传统微服务框架如何无缝过渡到服务网格 ASM

年复一年,为什么打破数据孤岛还是企业发展的首要任务
随机推荐
The cloud native landing practice of using rainbow for Tuowei information
NBI可视化平台快速入门教程(五)编辑器功能操作介绍
torch stack() meshgrid()
【DesignMode】单例模式(singleton pattern)
10 statistical methods commonly used for "dry goods" data analysis, with key application scenarios attached
Memory Limit Exceeded
How to configure webrtc video stream format playback in the new version of easygbs?
Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 1)
小球大小随机,随机运动碰撞
Neon optimization 2: arm optimization high frequency Instruction Summary
MySQL 索引测试
Opencv data type code table dtype
传统微服务框架如何无缝过渡到服务网格 ASM
「经验」爬虫在工作中的实战应用『实现篇』
RFFE中MIPI协议
Swin-transformer --relative positional Bias
Can go struct in go question bank · 15 be compared?
ANSI/UL 94 5-V级垂直燃烧试验
基于 actix、async-graphql、rbatis、pgsql/mysql 构建 GraphQL 服务(4)-变更服务
PC wechat multi open