求一SQL语句!

 所属目录:Java   |   类型:技术问答   |   时间:2007-05-21
 问题:

select   *     from   wl_company    
    where   c_id   not   in   (select   c_id   from   wl_userinfo   where   c_id   is   not   null)  
   
  有谁能提供一句实现同样功能的sql语句,但效率要高!  
  上面那条特慢!  
  谢谢!!

· 网友精彩回答:

发表者:jazzard

select   *   from   w1_userinfo   left   join   w1_company   on   w1_userinfo.c_id=w1_company.c_id     where  
  w1_company.c_id   is   null  
  对不起,这句可能符合你的要求

发表者:ice_berg16

select   c.c_id   from   w1_company   as   c  
  left   join   w1_userinfo   as   u   on   c.c_id=u.c_id  
  where   u.c_id   is   null

发表者:zhangyk1981

上面这个查询如果w1_userinfo.c_id字段有重复数据,查询结果会增多。试试下面这个:  
   
  select   c.c_id    
  from   w1_company   as   c    
  left   join   (select   distinct   c_id   from   w1_userinfo)   as   u    
  on   c.c_id=u.c_id  
  where   u.c_id   is   null;  
   
  不过搂主可以试试在子查询里用   distinct   ,可能效率会高一点。  
 

.
处理 SSI 文件时出错
© 2006-2008 All Rights Reserved