使用 exists 代替 in 是一个好的选择:
select num from a where num in(select num from b)
用下面的语句替换:
select num from a where exists(select 1 from b where num=a.num)

exists语法

用法: exists后面一定是子查询语句,不能用(值1,值2)代替;where exists (查询),结构中没有列;exists后面的子查询不返回任何实际数据,只返回真或假,当返回真时 where条件成立,该条记录保留。
exists (查询),只要子查询不会空 则where条件就返回真。

标签: Exist查询 替代in


阿里云优惠主机

添加新评论

免责声明
本博客部分内容来自于互联网,不代表作者的观点和立场,如若侵犯到您的权益,请联系[email protected]。我们会在24小时内进行删除。