如何找到两个表之间的区别? [英] How to find the difference between two tables?

查看:60
本文介绍了如何找到两个表之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MySQL数据库5.1版.我有两个表 Table_A 总是将记录保留在其中. Table_B 将仅用于比较差异.是否有通过PHP提供的MySQL查询功能,该功能将比较行并告诉我 Table_B 上缺少哪些行.

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.

表_A

user    name
 1      bob
 1      joe
 1      sally
 1      matt

表B

user    name
 1      bob
 1      joe
 1      sally
 1      john

运行PHP查询时,如何比较 Table_A Table_B ? 我只需要告诉我matt不再存在,它将把john添加到 Table_A .

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?

谢谢.

推荐答案

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

这篇关于如何找到两个表之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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