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

如果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语句构成表名,那么最后系统仍会报错。

————————————————

如果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语句构成表名,那么最后系统仍会报错。 ————————————————
经验分享 程序员 微信小程序 职场和发展