判断一个表的数据不在另一个表中最优秀方法
2007-03-30 16:14
232 查看
select a.* from tbl1 a
left join tbl2 b
on a.key = b.key
where b.key is null
select A.* from TABL1 A
where not EXISTS(select 1 from TABL2 WHERE TABL2.[KEY]=TABL1.[KEY])
select a.* from tbl1 a
left join tbl2 b
on a.key = b.key
where b.key is null
还有一个问题
a.key = b.key 还是 b.key = a.key他们的区别是什么?
------------------------------------------------------------------------
没有区别,一样的,看着规范些.具体以哪个表为主进行的连接是由left/right join来指定的.
select A.* from TABL1 A
where not EXISTS(select 1 from TABL2 WHERE TABL2.[KEY]=TABL1.[KEY])
select A.* from tbl1 A,tbl2 where A.key > key or A.key < key
select a.* from tbl1 a
left join tbl2 b
on a.key = b.key
where b.key is null
会比
select A.* from TABL1 A
where not EXISTS(select 1 from TABL2 WHERE TABL2.[KEY]=TABL1.[KEY])
left join tbl2 b
on a.key = b.key
where b.key is null
select A.* from TABL1 A
where not EXISTS(select 1 from TABL2 WHERE TABL2.[KEY]=TABL1.[KEY])
select a.* from tbl1 a
left join tbl2 b
on a.key = b.key
where b.key is null
还有一个问题
a.key = b.key 还是 b.key = a.key他们的区别是什么?
------------------------------------------------------------------------
没有区别,一样的,看着规范些.具体以哪个表为主进行的连接是由left/right join来指定的.
select A.* from TABL1 A
where not EXISTS(select 1 from TABL2 WHERE TABL2.[KEY]=TABL1.[KEY])
select A.* from tbl1 A,tbl2 where A.key > key or A.key < key
select a.* from tbl1 a
left join tbl2 b
on a.key = b.key
where b.key is null
会比
select A.* from TABL1 A
where not EXISTS(select 1 from TABL2 WHERE TABL2.[KEY]=TABL1.[KEY])
相关文章推荐
- 判断一个表的数据不在另一个表中最优秀方法
- 判断一个表的数据不在另一个表中最优秀方法
- 判断一个表的数据不在另一个表中最优秀方法
- 判断一个表的数据不在另一个表中最优秀方法
- sql 判断一个表的数据不在另一个表中
- 判断一个类是否为另一个类的实例 instanceof关键字和isAssignableFrom方法的区别
- (数据库篇) SQL查询~ 存在一个表而不在另一个表中的数据
- (数据库篇) SQL查询~ 存在一个表而不在另一个表中的数据
- (数据库篇) SQL查询~ 存在一个表而不在另一个表中的数据
- SQL把一个表中数据更新到另一个表的多种方法
- sql将一个表中的数据插入到另一个表中的方法
- SQL把一个表中数据更新到另一个表的多种方法
- SQL查询存在一个表而不在另一个表中的数据
- SQL 存在一个表而不在另一个表中的数据
- 判断一个dataset的数据是否包含另一个dataset的数据
- C#判断一个字符串是否包含另一个字符串的方法
- oracle与sql server2000中不在同一个服务器上的数据库数据操作的方法对比
- Sql语句把一个表的某几列的数据存到另一个表里的方法
- lodash 判断一个数据是否包含另一个数组
- sql将一个表中的数据插入到另一个表中的方法