mysql 子查询中 使用 limit

如果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

原文地址:https://www.cnblogs.com/-mrl/p/12106183.html