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

如果返回結果為空則表示 兩邊數據一致


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM