+ -
当前位置:首页 → 问答吧 → 查询一个表的资料不存在另一个表

查询一个表的资料不存在另一个表

时间:2011-08-12

来源:互联网

SQL code

SELECT phoneno FROM table_a WHERE phoneno NOT IN (SELECT phoneno FROM table_b) AND id=1


这句SQL很慢,两个表都有过万纪录,还会死掉

应该怎样才会快?

作者: lochen   发布时间: 2011-08-12

select phoneno from table_a a where a.id=1 and not exists (select 1 from table_b b where a.phoneno=b.phoneno);

还是索引没建好

作者: xmxkkk   发布时间: 2011-08-12

create index xxx on table_a (id,phoneno)

作者: ACMAIN_CHM   发布时间: 2011-08-12

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

作者: ACMAIN_CHM   发布时间: 2011-08-12