我有一个A表里面有50万的数据,另外一个B表里面有100万的数据,他们都有一个url字段,我现在想比较出在B中的url比在A出现的所有url。
select * from A where  not  url in (select url from B)但是我如果直接这行这个sql语句,会出现程序一直不懂的现象,这么大量的数据如何更好的比较呢,我用的是mysql数据库。

解决方案 »

  1.   

    在B表上建 URL 的索引select * from A where not exists (select 1 from B where url=a.url)
      

  2.   

    b的url是否需要去重,能否用join?
      

  3.   

    create table td_list as
    select distinct url from Bcreate index id_url on td_list(url)select * from A where not exists (select 1 from B where url=a.url)