表A有1000条数据,有字段name,表B有200多W条数据,也有字段name
现在查询出没在表B中出现的name有哪些
select ID,name from A where name not in(select distinct(name) from B)查询出100多条记录,要1分多钟,速度很慢
单独运行select ID,name from A 和
select distinct(name) from B都只用1秒,select distinct(name) from B 查出来的name大概有900个
现在查询出没在表B中出现的name有哪些
select ID,name from A where name not in(select distinct(name) from B)查询出100多条记录,要1分多钟,速度很慢
单独运行select ID,name from A 和
select distinct(name) from B都只用1秒,select distinct(name) from B 查出来的name大概有900个
select ID,name from A where not exists(select 1 from B where name = a.name)
这个效率差不多,B表中有索引,要不单独查询它不会就1秒钟
select a.id,a.name from a inner join b on a.name=b.name
select a.id,a.name from a left join b on a.name=b.name where b.name is null
这样查询出来的就对了,查询时间就用了1秒