Union与Union all区别

准备两张表

tableA			                  tableB
id  name  score             id  name  score
1   a    80               1    d    48
2    b    79               2   e    23
3    c     68               3   c    86

采用union查询

select name from tableA             
union                        
select name from tableB 

查询结果
name
a
d
b
e
c

采用union all查询

select name from tableA
union all
select name from tableB
查询结果
name
a
b
c
d
e
c

总结
(1)union会将联合的结果集去重,效率较union all差
(2)union all不会对结果集去重,所以效率高

猜你喜欢

转载自blog.csdn.net/qq_46548855/article/details/107677816