mysql where in limit_mysql实现in子句的limit查询 (转)

在supesite里面执行一个SQL语句: select * from supe_spaceitems where catid=98 and itemid not in(select itemid from supe_spaceitems where catid=98 and haveattach=1 order by itemid desc limit 1) order by itemid desc limit 3;

发现如下提示:#1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

原因:发现mysql不支持in子句的limit查询

于是,修改语法如下:select * from supe_spaceitems where catid=98 and itemid not in(select t.itemid from(select * from supe_spaceitems where catid=98 and haveattach=1 order by itemid desc limit 1) as t) order by itemid desc limit 3;

在MySQL4.1中子查询是不能使用LIMIT的,手册中也明确指明 “This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME subquery’ ”

也就是说,这样的语句是不能正确执行的。 select * from table where id in (select id from table limit 10);

但是,,但是,,,只要你再来一层就行。。如: select * from table where id in (select t.id from (select * from table limit 10)as t)

你说说,MySQL是不是很让人无语??

经本人测试使用,该方法不错!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值