如何使用MySQL语句查找两个MySQL表之间的差异? [英] How to find difference between two MySQL tables using MySQL statement?

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

问题描述

我有两个名为MytableA和MytableB的表. MytableA保留609行,而MytableB保留607行.两行具有相同的结构.我只想找出MytableA中不存在的imageURL,并显示那些缺失的行?谁能告诉我什么MySQL语句来显示MytableB中缺少的那些行?

I have two tables called MytableA and MytableB. MytableA holds 609 rows and MytableB holds 607 rows. Both Rows have same structure. I just want to find out what imageURL(s) exist in MytableA that don't exist in MytableB and display those missing rows? Could anyone tell me what is the MySQL statement to display those rows that are missing in MytableB?

CREATE TABLE IF NOT EXISTS `MytableA` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(32) DEFAULT NULL,
  `bio` varchar(90) DEFAULT NULL,
  `website` varchar(90) DEFAULT NULL,
  `profile` varchar(90) NOT NULL,
  `fullname` varchar(250) DEFAULT '',
  `diffId` varchar(250) NOT NULL DEFAULT '',
  `imageUrl` varchar(250) NOT NULL DEFAULT '',
  `PageURL` varchar(250) NOT NULL DEFAULT '',
  `CreatedTime` varchar(250) NOT NULL DEFAULT '',
  `imageTags` varchar(250) NOT NULL DEFAULT '',
  `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`ID`)
)

推荐答案

SELECT *
  FROM MyTableA
 WHERE imageURL NOT IN (SELECT imageURL FROM MyTableB)

也许有更快的方法,但这具有简洁的优点.

There may be faster ways to do it, but this has the merit of succinctness.

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

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