关于mysql 子查询中 使用 limit

时间:2022-10-23 09:50:08

在MySQL 8.0中 子查询是不能使用LIMIT的
在 子查询中使用limit后,执行会报错 “This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME subquery’ ”

也就是说,这样的语句是不能正确执行的。
select * from table where id in (select id from table limit 10);

但是,只要在 limit子查询语句的外面 再来一层就行。。如:
select * from table where id in (select t.id from (select * from table limit 10)as t);