Mysql子查询用limit

时间:2021-12-14 02:25:04

执行带有Limit子查询是有问题的:

  SELECT * FROM task_and_device  WHERE  job_id IN
(SELECT id FROM wx_device_task_job WHERE user_id=79269 AND STATUS=1 ORDER BY last_updated DESC LIMIT 20 OFFSET 0)

报了如下的错误:

错误码: 1235
This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'



需要再加上一层select才能成功:

  SELECT * FROM task_and_device  WHERE  job_id IN
(
SELECT A.id FROM
(
SELECT id FROM wx_device_task_job WHERE user_id=79269 AND STATUS=1 ORDER BY last_updated DESC
LIMIT 20 OFFSET 0
) AS A
)