如果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语句构成表名,那么最后系统仍会报错。
本文介绍了解决MySQL中使用LIMIT与IN子句时出现的错误问题。通过两个实用的方法来避免错误:一是增加一层子查询;二是将限制条件放在FROM子句中而不是WHERE子句中。
593

被折叠的 条评论
为什么被折叠?



