1

mysql union all 比较两个表不同的数据

 1 year ago
source link: http://abcdxyzk.github.io/blog/2023/01/03/mysql-union-all/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

mysql union all 比较两个表不同的数据

2023-01-03 16:57:00

https://blog.csdn.net/JustDI0209/article/details/122492293

https://blog.csdn.net/u010931123/article/details/82425580

select * from (select * from rs.zzdmk union all select * from rs2.zzdmk) t group by pbf, sxh HAVING count(*)=1;

count( * ) = 1 为两张表数据不同的地方(只有一条结果),count( * ) = 2 为两张表数据相同的地方。

union和union all的区别

union会自动压缩多个结果集合中的重复结果,而union all则将所有的结果全部显示出来,不管是不是重复。

Union

对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序;

UNION在进行表链接后会筛选掉重复的记录,所以在表链接后会对所产生的结果集进行排序运算,删除重复的记录再返回结果。

实际大部分应用中是不会产生重复的记录,最常见的是过程表与历史表UNION

Union All

对两个结果集进行并集操作,包括重复行,不进行排序;

如果返回的两个结果集中有重复的数据,那么返回的结果集就会包含重复的数据了。

Posted by kk

2023-01-03 16:57:00tools, mysql

« mysql查询时排除某个字段 ASPMyAdmin web管理sqlserver »

wx_ok.pngali_ok.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK