sql server 查询优化

  业务需求,查询A表中ID在B表中没有的数据。即A、B交叉,取非交叉部分的A。

  刚开始的思路是A Left join B where B.Number IS NULL 。

  显而易见A是张大表,B也是,再加上关联了其他很多表,就慢了,最终决定对B表下手,更改查询方式未exists,即:

  A where not exists (select 1 from B where A.Number =B.Number )

  改写之后果然快了很多。

  exists 和 in 功能类似,但效率差距很大, 这里推荐使用exists。

posted @ 2020-05-26 22:38  顾星河  阅读(233)  评论(0编辑  收藏  举报