简体   繁体   中英

How to find the difference between two tables?

I have a MySQL database ver 5.1. I have two tables Table_A will always keep the records in it. Table_B will be used to only compare the differences. Is there a MySQL query function via PHP that will compare the rows and tell me what rows are missing on Table_B .

Table_A

user    name
 1      bob
 1      joe
 1      sally
 1      matt

Table_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 ? All I need is to tell me that matt no longer exists and it will add john to Table_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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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