当前位置:网站首页>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
边栏推荐
- Business Intelligence BI and business management decision-making thinking 4: business cost analysis
- CODING 正式入驻腾讯会议应用市场!
- 「干货」数据分析常用的10种统计学方法,附上重点应用场景
- ros advertise 发布数据小技巧--latch配置
- Brief introduction of Feature Engineering in machine learning
- Unity技术手册-初探性能优化
- CTF flow analysis common questions (II) -usb flow
- com. alibaba. fastjson. Jsonobject tojsonstring eliminate circular reference
- Personally test the size of flutter after packaging APK, quite satisfied
- 「经验」爬虫在工作中的实战应用『实现篇』
猜你喜欢
联想YOGA 27 2022,超强配置全面升级
Business Intelligence BI and business management decision-making thinking 4: business cost analysis
Redis beginner to master 01
20220528【聊聊假芯片】贪便宜往往吃大亏,盘点下那些假的内存卡和固态硬盘
链表中环的入口结点-链表专题
Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 1)
German agbb VOC hazardous substances test
Lenovo Yoga 27 2022, full upgrade of super configuration
云上“视界” 创新无限 | 2022阿里云直播峰会正式上线
20220607跌破建议零售价,GPU市场正全面走向供过于求...
随机推荐
华兴证券:混合云原生架构下的 Kitex 实践
MySQL download and installation tutorial
Influence and requirements of different manufacturing processes on the pad on PCB
The cloud native landing practice of using rainbow for Tuowei information
德国AgBB VoC有害物质测试
Coding officially entered Tencent conference application market!
go之web框架 iris
Ditto设置全局仅粘贴文本快捷键
「经验」爬虫在工作中的实战应用『实现篇』
How to seamlessly transition from traditional microservice framework to service grid ASM
Development: how to install offline MySQL in Linux system?
企业选型作业上常犯的一个错误
TCP粘包问题
Practical application of "experience" crawler in work "theory"
ANSI/UL 94 5-V级垂直燃烧试验
3.10 haas506 2.0 development tutorial example TFT
MySQL recursion
torch. roll
CODING 正式入驻腾讯会议应用市场!
com. alibaba. fastjson. Jsonobject tojsonstring eliminate circular reference