zoukankan      html  css  js  c++  java
  • 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是不是很让人无语??

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

  • 相关阅读:
    LeetCode 260
    LeetCode 258
    LeetCode 237
    LeetCode 226
    LeetCode 203
    LeetCode 202
    codeforces 7D
    codefroces 7C
    codeforces 7B
    codeforces 6E (非原创)
  • 原文地址:https://www.cnblogs.com/lovefan/p/3680819.html
Copyright © 2011-2022 走看看