业务需求,查询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。

相关文章:

  • 2021-07-06
  • 2022-12-23
  • 2022-01-05
  • 2021-12-11
猜你喜欢
  • 2021-07-17
  • 2022-12-23
  • 2021-04-01
  • 2021-09-27
  • 2021-12-04
  • 2021-12-01
相关资源
相似解决方案