有两个表,表A和表B,字段定义如下:
表A字段:(ID,Name, NetKey);
表B字段:(ID,Name,Plug,Group,);现要查询表B中符合条件的纪录,且这些纪录在表A中,我用IN,查的太慢了,有没有其他更好的办法呢
我的语句是这样写的
Select distict A.NetKey form A where A.Name IN(Select B.Name from B where Plug=1, Group=4);谢谢

解决方案 »

  1.   

    Select distict A.NetKey form A left join B on A.Name=B.Name where Plug=1, Group=4
      

  2.   

    用join比in快一点。
    select distict A.NetKey form A inner join B on a.name=b.name
      

  3.   


    select distict A.NetKey form A inner join B on a.name=b.name where Plug=1, Group=4
      

  4.   

    select distict A.NetKey form A ,B where  a.name=b.name and Plug=1 and Group=4
      

  5.   

    Select distict A.NetKey 
    from A , b 
    where A.Name = B.Name and b.Plug=1 and b.Group=4