当前位置:首页 > 数据库 > 正文

mysql 子查询中 使用 limit

2020-02-11 数据库

 

如果sql语句中的子查询包含limit 

例如: select * from a where id in (select id from b limit 3) 

会报错:This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME subquery‘ #

解决办法:

1、加一层子查询 

例如:select * from a where id in (select t.id from (select id from b limit 3 )as t) 

2、把限制条件放到from而非where子句中,就不必出现嵌套再嵌套。 

例如:select * from (select id from a limit 3) as foo

 

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/SQL/14187.html