比较两个相同的表MySQL [英] Compare two identical tables MySQL

查看:198
本文介绍了比较两个相同的表MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在表中进行数据转换,这就是为什么我创建了一个新表的原因,该表与旧表相同,但为空.

I'm currently in the process of converting data, in a table, which is why I've created a new table, identical to the old one, but empty.

我已经运行了数据转换器,但行数有所不同.

I've run my data converter, and I have a difference in row count.

如何选择与两个表不同的所有行,而忽略主键标识符(每个条目都不同).

How do I select all rows that are different from the two tables, leaving out the primary key identifier (that differs on every entry).

推荐答案

select * from (
SELECT 'Table1',t1.* FROM table1 t1 WHERE 
(t1.id)
NOT IN (SELECT  t2.id FROM table2 t2)
UNION ALL
SELECT 'Table2',t2.* FROM table2 t2 WHERE   
(t2.id) 
NOT IN (SELECT  t1.id FROM table1 t1))temp order by id;

您可以在其中的列中添加更多列以检查更多信息. 尝试看看是否有帮助.

You can add more columns in where columns to check on more info. Try and see if this helps.

这篇关于比较两个相同的表MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆