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