t1有10万条信息,t2有3万条信息,如何快速实现t1中是否存在t2信息的查询?这个功能每天都要使用,不知道怎么查询速度最快?

解决方案 »

  1.   

    select *
    from t1 
    where exists (select 1 from t2 where id=t1.id);不是主键。则加上索引。
      

  2.   

    具体要求是怎样的呢
    如果找到重复数据了 然后怎么办呢
    SQL> select * from t1;        ID NAME
    ---------- ----------
             1 wh
             2 wp
             3 wrSQL> select * from t2;        ID NAME
    ---------- ----------
             2 wq
             3 wh
             4 ww
    SQL> select count(1) from
      2  t1,t2
      3  where t1.id=t2.id;  COUNT(1)
    ----------
             2
    SQL> select count(1) from
      2  t1,t2
      3  where t1.name=t2.name;  COUNT(1)
    ----------
             1
      

  3.   

    select t1.pk from t1 where exists (select 1 from t2 where t2.字段=t1.对应字段);exists 最快。
      

  4.   


    给大表建立索引,小表放在前面,大表放在后面,用exist效率最高。感谢大家的帮助!
      

  5.   

    就你这个sql而言,在cbo下,谁在前面,用in还是exists,是无所谓的。
      

  6.   

    晕,怎么写这里了?都是ACMAIN_CHM害的,说什么熊猫党兔子党……