当前位置:Gxlcms > 数据库问题 > mysql 对比两个表的一致性

mysql 对比两个表的一致性

时间:2021-07-01 10:21:17 帮助过:72人阅读

-- 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

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

mysql 对比两个表的一致性

标签:没有   --   null   使用   sel   select   查询   left join   对比   

人气教程排行