mysql not in用法


 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;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM