Search code examples
phpmysqlisql-in

How to use limit and offset in SQL IN operator subquery?


For example:

SELECT groupdate
FROM ccl9t_az_articles
WHERE groupdate IN (
   SELECT * FROM ccl9t_az_articles LIMIT 3 OFFSET 2
)
GROUP BY groupdate

What is the correct way?


Solution

  • In the error display above code returns the following

    MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery

    The problem was fixed by changing the above code to:

        SELECT * FROM ccl9t_az_articles as group1 INNER JOIN (
    SELECT groupdate FROM ccl9t_az_articles LIMIT 3 OFFSET 2
    ) 
    as group2 ON group1.groupdate = group2.groupdate GROUP BY group1.groupdate