union all和union的区别以及怎么使用

union all和union的区别以及怎么使用,第1张

一、区别1:

1、union: 对两个结果集进行并集 *** 作, 不包括重复行,相当于distinct;

2、union all: 对两个结果集进行并集 *** 作,, 不管是不是重复;

二、区别2:

1、union: 会对获取的结果进行排序 *** 作

2、union all: 不会对获取的结果进行排序 *** 作

三、区别3:

1、union看到结果中ID=3的只有一条(这里不会把id=3去重了一个)

select * from student where id < 4

union

select * from student2 where id > 2 and id < 6

2、union all 结果中ID=3的结果有两个

select * from student where id < 4

union all

select * from student2 where id > 2 and id < 6

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1298998.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存