Select * from table 1 where ID not in (Select ID from table2) 改为用 not Exists 怎么写?

xscansou 2007-12-02 03:47:08
Select * from table 1 where ID not in (Select ID from table2) 改为用 not Exists 怎么写?
...全文
1245 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hedy821 2008-02-03
  • 打赏
  • 举报
回复
学到了
pt1314917 2008-01-26
  • 打赏
  • 举报
回复
发表于:2007-12-02 15:47:08
----------------------------
无语,这么久了都没结帖。。。
12月份的帖子都被你们翻出来了,实在太强悍了。。。
wuabc0954 2008-01-26
  • 打赏
  • 举报
回复
select * from table1 a where not exists (Select top 1 1 from table2 b where a.id=b.id)

我验证过了,这个语句的资源消耗最少。
ojuju10 2007-12-03
  • 打赏
  • 举报
回复
Select * from table1 a where not exists (Select 1 from table2 b where a.id=b.id)
Gangzai1983 2007-12-03
  • 打赏
  • 举报
回复
pt1314917 2007-12-02
  • 打赏
  • 举报
回复
恩。楼上两种方法都可以达到楼主要求,效率也比搂主原来的高
Limpire 2007-12-02
  • 打赏
  • 举报
回复
--> 这个应该效率更高
select a.* from table1 a left join table2 b on a.id=b.id where b.id is null
wzy_love_sly 2007-12-02
  • 打赏
  • 举报
回复
select * from table a where not exists(select 1 from table2 b where a.id=b.id)

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧