查找一个表中存在而另一个表中不存在的记录
2011-12-07 13:48
441 查看
例如:两个表:t1, t2 ,查询在表t1中存在,而在表t2中不存在的记录。
假设以id字段为关联字段。
方法1:需要两个表的字段完全一致
select *
from t1
minus
selecct * from t2
方法2:
select * from t1
where not exists(select 1 from t2 where t1.id=t2.id)
方法3:
select * from t1
where id not in(select id from t2)
方法4:需要t2.id不能为空
select t1.*
from t1
left join t2 on t1.id=t2.id
where t2.id is null
假设以id字段为关联字段。
方法1:需要两个表的字段完全一致
select *
from t1
minus
selecct * from t2
方法2:
select * from t1
where not exists(select 1 from t2 where t1.id=t2.id)
方法3:
select * from t1
where id not in(select id from t2)
方法4:需要t2.id不能为空
select t1.*
from t1
left join t2 on t1.id=t2.id
where t2.id is null
相关文章推荐
- SQL:查找一个表中存在而另一个表中不存在的记录
- 查找一个表中存在而另一个表中不存在的记录
- 找在一个表中存在而另一个表中不存在的记录
- 存在于一个表而不存在于另一个表中的数据
- SQL语句技巧:查询存在一个表而不在另一个表中的数据记录
- 给定一个经过一次旋转的有序数组,从中查找一个值,若存在返回它的索引,不存在返回-1
- 给定一个经过一次旋转的有序数组,从中查找一个值,若存在返回它的索引,不存在返回-1,假定数组存在重复元素
- SQL语句技巧:查询存在一个表而不在另一个表中的数据记录
- 查询一个表里的每条记录在另一个表里是否存在,在返回1,不在返回0
- 查找程序所在上一级目录中是否存在指定文件夹,不存在就建立,并在其中新建一个txt文件
- 查询存在于一个表而不存在于另一个表中的数据
- [SQL] 如何在SQL Server2005数据库中检查一个表是否存在,如存在就删除表记录,如不存在就建表.
- MySQL插入数据时,如果记录不存在则insert,如果存在则update
- 发布一个List记录查找Web Part: PowerSearch v1.0
- EasyUI配置当点击一个datagrid的checkbox选中或取消选中记录的时候刷新另一个datagrid数据的方法
- mongo-java-driver-3 记录存在则更新,不存在创建
- 判断用户是否存在不存在添加存在返回一个值
- mysql 存在该记录则更新,不存在则插入记录的sql
- MySQL 记录不存在插入 和 存在则更新和
- 在vc6中检查一个目录是否存在,如果不存在就创建该目录