今天看项目代码里面有许多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)
SQL优化:in语句转exists提高效率
本文介绍了一种将SQL查询中的in语句转换为exists语句的方法,以提升查询效率,特别是当in语句包含大量元素时。
26万+

被折叠的 条评论
为什么被折叠?



