SELECT phoneno FROM table_a WHERE phoneno NOT IN (SELECT phoneno FROM table_b) AND id=1这句SQL很慢,两个表都有过万纪录,还会死掉应该怎样才会快?

解决方案 »

  1.   

    select phoneno from table_a a where a.id=1 and not exists (select 1 from table_b b where a.phoneno=b.phoneno);还是索引没建好
      

  2.   

    create index xxx on table_a (id,phoneno)
      

  3.   

    SELECT a.phoneno 
    FROM table_a a inner join table_b b on a.phoneno=b.phoneno
    WHERE a.id=1
      

  4.   

    SELECT phoneno FROM table_a a left join table_b b
    on a.phoneno=b.phoneno 
    WHERE b.phoneno is null AND a.id=1
    phoneno、ID上建立索引