a,b两张表中都有ac_id选出所有b表中有而a表中没有的ac_id
注意a,b两表中都有数十万条记录,不能用not in 

解决方案 »

  1.   

    select ac_id from b
    where not exists(select null from a where a.ac_id=b.ac_id)
      

  2.   

    where not exists(select null from a where a.ac_id=b.ac_id)
    满足条件:不存在a中的ac_id等于b中的ac_id 
    a,b两张表中都有ac_id选出所有b表中有而a表中没有的ac_id
    与你的条件等价的
      

  3.   

    哦,明白了,那么这个not exists语句的复杂度是多少呢
    另外 要用not in的复杂度又是多少呢,谢谢了
      

  4.   

    a.ac_id=b.ac_id
    有这个条件就可以避免全表扫描 如果ac_id上有索引那就更好了
    用in的 是要全表扫描的具体的你看执行计划就知道了