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

 

posted @ 2019-12-27 10:59  一个人的孤独自白  阅读(5757)  评论(0编辑  收藏  举报