如
我要查询 Sendorder表中的冗余数据(没有和reg_person或worksite相连的数据)
sql="select Sendorder.id,Sendorder.reads,Sendorder.addtime from Sendorder where Sendorder.person_id not in(select user_id from reg_person ) or Sendorder.worksite_id not in(select id from worksite) order by Sendorder.addtime desc"
程序执行时间:40109.38毫秒
sql="select Sendorder.id,Sendorder.reads,Sendorder.addtime from Sendorder where not EXISTS (SELECT id FROM reg_person where reg_person.user_id=Sendorder.person_id) or not EXISTS (SELECT id FROM worksite where worksite.id=Sendorder.worksite_id) order by Sendorder.addtime desc"
程序执行时间:8531.25毫秒
很明显使用not EXISTS效率高多了