not in 和 not exists

--一个连接查询,在Bn_scenes中去掉一些记录。
select * from UFSystem..BN_Scenes where bSysVisible='1' and cBizSceneId not in (select cBizSceneId from BN_ScenesCustom where userid='likun5') order by iorder asc

 

使用exists

select * from UFSystem..BN_Scenes where bSysVisible='1' 
and  not exists(select 
cBizSceneId from BN_ScenesCustom where userid='demo' AND BN_Scenes.cBizSceneId=BN_ScenesCustom.cBizSceneId) 

两个查询执行的结果和效率一样。

原文地址:https://www.cnblogs.com/363546828/p/3069610.html