怎么查询在A表中不存在的B表的数据(id+bm两个条件)
2017-11-24 09:20
369 查看
如何查询在A表中不存在的B表的数据(id+bm两个条件)
A 表
id bm
1 2
1 3
1 4
b表
id bm
1 2
1 3
1 4
1 5
1 6
如何查询在A表中不存在的B表的数据(id+bm两个条件)
如图的话就是
1 5
1 6
------解决方案--------------------
SQL code
A 表
id bm
1 2
1 3
1 4
b表
id bm
1 2
1 3
1 4
1 5
1 6
如何查询在A表中不存在的B表的数据(id+bm两个条件)
如图的话就是
1 5
1 6
------解决方案--------------------
SQL code
select b.* from b where not exists(select 1 from a where a.id=b.id and a.bm=b.bm) ------解决方案-------------------- SQL codeselect * from a where not exists(select 1 from tb where id=a.id and bm=a.bm) ------解决方案-------------------- SQL codeselect * from b except select * from a ------解决方案-------------------- select * from A where checksum(id, bm) not in (select checksum(id, bm)from B) ------解决方案-------------------- SQL codeselect * from B WHERE NOT EXISTS (SELECT 1 FROM A WHERE id = B.id AND bm = B.bm) ------解决方案-------------------- SQL codeselect * from a where checksum(*) not in(select checksum(*) from b)
相关文章推荐
- sql查询ID=1与数据后几条,并且将查询的两个数据显示在一个查询窗口中
- php中mysql一条sql语句查询出所有符合条件的数据,该怎么写?
- 和SQL内连接不同,SQL外连接返回到查询结果集合中的不仅包含符合连接条件的行,而且还包括左表(左外连接时)、右表(右外连接时)或两个边接表(全外连接)中的所有数据行,下面就为您详细介绍SQL外连接,
- mysql 查询两个表相同数据 全部数据 查询一个表中另外一个表不存在的数据
- 查询数据时,根据不同查询条件的情况,重载方法的一种写法(不知道怎么描述了!!!!)
- Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询
- 项目产品化升级数据库脚本问题——如何查询两个数据库差异的库表或者数据
- Java ssh poi 根据条件查询数据导出excel到浏览器 下载框不显示 浏览器乱码 之前是用submit()
- 机房收费系统之—如何查询两个日期之间的数据
- 从一个表中筛选包含多条数据的条件查询
- (转)查询A、B表中,A表中存在B表不存在的数据
- mongo里面根据对象字段的ID查询 db.Photo.find({'owner.$id':ObjectId('xxxx')}) , 并且使用forEach循环修改查询的数据
- yii根据id查询一条数据
- 假设对testid有更新则插入一条新记录,那么怎么查询出testid最后的状态(分组查询)
- bootstrap-table前端实现多条件时间段查询数据
- Chapter 10. WinForm-DataGridView(确认删除、多条件查询、数据区别显示)
- Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询
- ###(很难找的页面错误)查询操作不需要 返回 操作成功后失败。【方法不能同时执行两个response返回两次数据。导致页面显示数据失败】
- SQL查询一个表中另外一个表不存在的数据。
- django orm多条件查询及except处理不存在记录的样码