mysql 对比两个表的一致性

-- A和B两个表 数据是否一致
select 自定义
from A left join B on A.id = B.id
where B.id is null

注释:这样查询的结果是A表中有而B表中没有的数据


select 自定义
from B left join A on A.id = B.id
where A.id is null

注释:这样查询的结果是B表中有而A表中没有的数据

可以使用一个sql完成

select 自定义
from A left join B on A.id = B.id
where B.id is null
union all
select 自定义
from B left join A on A.id = B.id
where A.id is null

如果返回结果为空则表示 两边数据一致

原文地址:https://www.cnblogs.com/invban/p/6646825.html