From: http://blog.chinaunix.net/uid-22414998-id-2945656.html

This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME 错误解决
 
这次国庆节回来后的测试中,在一个Mysql表达式中使用嵌套查询,出现了这个错误。原因是内层select语句带有limit子句。
 
在网上查了下,有文章指出:
  • 比如这样的语句是不能正确执行的。
  • select * from table where id in (select id from table limit 12);
  • 但是,只要你再加一层就行。如:
  • select * from table where id in (select t.id from (select * from table limit 12)as t)
  • 这样就可以绕开limit子查询的问题。
  • 问题解决。
  • 后来我发现,上述是解决问题的一个方法,其实还有一个更好的做法,就是把限制条件放到from而非where子句中,就不必出现嵌套再嵌套。
    如上例,可以改为:
  • select * from (select id from table limit 12) as foo;
  • 注意:其实as foo特别重要,如果不写成from () as xxx的形式,即不给from后的select语句构成表名,那么最后系统仍会报错。
     
     

    相关文章:

    • 2022-12-23
    • 2022-02-23
    • 2022-12-23
    • 2021-10-03
    • 2022-12-23
    • 2021-10-16
    猜你喜欢
    • 2021-07-30
    • 2021-09-29
    • 2021-10-25
    • 2022-12-23
    • 2022-12-23
    • 2021-07-14
    相关资源
    相似解决方案