union和union all的区别


一、引言

union关键字用来连接多个结果集,union和union all的区别在于:union 对两个结果集进行并集操作,重复数据只显示一次;Union All,对两个结果集进行并集操作,重复数据全部显示。

二、测试步骤

1.student表

2.union

select * from stu where stuNo <= 'b10050505'
union
select * from stu where stuNo >= 'b10050505'

3.union all

select * from stu where stuNo <= 'b10050505'
union all
select * from stu where stuNo >= 'b10050505'

三、结论

可以发现使用union进行连接的结果集没有重复数据b10050505,而使用union all进行连接的结果集中含有重复数据b10050505

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM