您的位置:首页 > 其它

判断一个表的数据不在另一个表中最优秀方法

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])
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: