Home  >  Article  >  php教程  >  mysql用了not in为啥查不出数据

mysql用了not in为啥查不出数据

WBOY
WBOYOriginal
2016-06-06 19:42:461124browse

mysql用了not in为什么查不出数据。 selectid,cid,title,keywords,hits,addtimefrom`Articles`whereidnotin(4454,4453,4452,4451,4450,4449,4448,4447)orderbyaddtimedesc,iddescLIMIT0,18 上面的语句去掉notin就有数据。这是为什么。数据库里有4000多条数据

mysql用了not in为什么查不出数据。
select id,cid,title,keywords,hits,addtime from `Articles` where id not in(4454,4453,4452,4451,4450,4449,4448,4447)  order by addtime desc ,id desc LIMIT 0 , 18


上面的语句去掉not in就有数据。这是为什么。 数据库里有4000多条数据,编号从 1到4454。不可能查不出的。而且之前没事,突然就查不出了。很奇怪。
------解决思路----------------------
貌似mysql中的not in 存在一定的bug。我之前也碰到过,直接not in(values) 查询出的结果是0条
可以试试这样:
建一个新表如ids 只有一个id字段,把4454,4453,4452,4451,4450,4449,4448,4447插进去,然后这样查询:
select id,cid,title,【本文来自鸿网互联 (http://www.68idc.cn)】keywords,hits,addtime from `Articles` where id not in(select id from ids)  order by addtime desc ,id desc LIMIT 0 , 18;
我之前就是这么做的,希望能帮到你
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn