`
El_Nino
  • 浏览: 200542 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

sql中的in转为exists语句

阅读更多

今天看项目代码里面有许多in的sql语句,效率比较低,而且in里面的内容比较多的时候也会引发异常。

这里记一下in转为exists的方法:

 

原始sql语句:

select * from t where id in (1,2,3,4,5)

 转化成exists后,

  

select * from twhere id exists (select * from (select 1 as x union select 2 union select 3 union select 4 union select 5)tmp where tmp.id = t.id)

 

1
4
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics