一、引言
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