简体   繁体   English

如何找到两个表之间的区别?

[英]How to find the difference between two tables?

I have a MySQL database ver 5.1. 我有一个MySQL数据库5.1版。 I have two tables Table_A will always keep the records in it. 我有两个表Table_A始终将记录保留在其中。 Table_B will be used to only compare the differences. Table_B将仅用于比较差异。 Is there a MySQL query function via PHP that will compare the rows and tell me what rows are missing on Table_B . 是否有通过PHP的MySQL查询函数,该函数将比较行并告诉我Table_B缺少哪些行。

Table_A 表_A

user    name
 1      bob
 1      joe
 1      sally
 1      matt

Table_B 表_B

user    name
 1      bob
 1      joe
 1      sally
 1      john

When the PHP query was run how would I compare Table_A vs Table_B ? 运行PHP查询时,如何比较Table_ATable_B All I need is to tell me that matt no longer exists and it will add john to Table_A . 所有我需要的是告诉我, matt不再存在,它会增加john表-A。

What would be the best way to do this? 最好的方法是什么?

Thanks. 谢谢。

SELECT name FROM Table_A WHERE name NOT IN (SELECT name FROM Table_B)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM