您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2024/6/15 22:54:39发布29次查看
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;
我之前就是这么做的,希望能帮到你
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product