--not in 和not exists 如果查询语句使用了not in 那么内外表都进行全表扫描,没有用到索引;而not extsts 的子查询依然能用到表上的索引。所以无论那个表大,用not exists都比not in要快。
--NOT  IN 
select * from  OrderAsst A  where A.OrgGid  NOT IN( select A.OrgGid from  Org B  WHERE A.OrgGid=B.Gid )   AND A.Status='正常'
--NOT EXISTS
select * from OrderAsst A  where NOT EXISTS(select A.OrgGid from Org B  WHERE A.OrgGid=B.Gid) AND A.Status='正常'
--
--  IN 
select * from  OrderAsst A  where A.OrgGid   IN( select A.OrgGid from  Org B  WHERE A.OrgGid=B.Gid )   AND A.Status='正常'
--EXISTS
select * from OrderAsst A  where EXISTS(select A.OrgGid from Org B  WHERE A.OrgGid=B.Gid) AND A.Status='正常'

 

相关文章:

  • 2022-01-17
  • 2021-10-27
  • 2021-10-14
  • 2022-03-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-23
  • 2021-10-02
  • 2022-01-22
  • 2021-10-11
  • 2021-06-06
相关资源
相似解决方案