mysql子查询不支持limit问题解决

    xiaoxiao2021-03-25  119

    如果sql语句中的子查询包含limit 例如: select * from table where id in (select id from table limit 3) 会报错:This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME

    解决办法:

    1、加一层子查询 例如:select * from table where id in (select t.id from (select * from table limit 3)as t) 2、把限制条件放到from而非where子句中,就不必出现嵌套再嵌套。 例如:select * from (select id from table limit 3) as foo

    注意:其实as foo特别重要,如果不写成from () as xxx的形式,即不给from后的select语句构成表名,那么最后系统仍会报错。
    转载请注明原文地址: https://ju.6miu.com/read-18678.html

    最新回复(0)