首页 > 数据库技术 > 详细

mysql not in用法

时间:2014-06-06 07:43:28      阅读:479      评论:0      收藏:0      [点我收藏+]

 select * from zan where uid not in(select uid from zan where zhongjiang !=0) group by uid order by rand() limit 40

不过这个执行效率比较低,正在找更好用的方法

 

 

我觉得还是不如两条语句分开来写,先查出所有的uid,然后再用not in  这样查询速度快很多

$sql="select uid from zan where zhongjiang !=‘0‘";
$res=$dbs->query($sql);
$uid=‘‘;
while($o=$dbs->fetch_object($res)){
    $uid.=$o->uid.‘,‘;
}
$uid=substr($uid,0,strlen($uid)-1);
$sql="select * from zan where uid not in($uid) group by uid order by rand() limit 40";
$res=$dbs->query($sql);
$arr=array();
while($o=$dbs->fetch_object($res)){
    $arr[]=$o;
}

mysql not in用法,布布扣,bubuko.com

mysql not in用法

原文:http://www.cnblogs.com/myphper/p/3767578.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!