Home > Database > Mysql Tutorial > How to Resolve MySQL Error 1235: 'LIMIT & IN/ALL/ANY/SOME subquery' Not Supported?

How to Resolve MySQL Error 1235: 'LIMIT & IN/ALL/ANY/SOME subquery' Not Supported?

Susan Sarandon
Release: 2024-12-13 22:33:10
Original
865 people have browsed it

How to Resolve MySQL Error 1235:

Error: "This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'"

When executing a PHP query that utilizes a subquery with a LIMIT clause and an IN operator, you may encounter an error like this:

Error during SQL execution: SELECT VID, thumb FROM video WHERE VID IN ( SELECT VID FROM video WHERE title LIKE "%funny%" ORDER BY viewtime DESC LIMIT 5) ORDER BY RAND() LIMIT 1

MySQL Error: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

MySQL Errno: 1235
Copy after login

This error occurs because certain versions of MySQL do not support subqueries with a LIMIT clause used in conjunction with IN, ALL, ANY, or SOME operators.

Solution

To resolve this issue, consider using a JOIN instead of a subquery:

SELECT v.VID, v.thumb
FROM video AS v
INNER JOIN
     (SELECT VID
     FROM video
     WHERE title LIKE "%'.$Channel['name'].'%"
     ORDER BY viewtime DESC
     LIMIT 5) as v2
  ON v.VID = v2.VID
ORDER BY RAND()
LIMIT 1
Copy after login

This modified query uses an INNER JOIN to combine the results of two SELECT statements. The first SELECT statement fetches the VID of videos whose titles contain the specified channel name, ordering them by view time in descending order and limiting the results to the first 5. The second SELECT statement then uses this VID list to filter the main result set, fetching specific columns from the video table.

The above is the detailed content of How to Resolve MySQL Error 1235: 'LIMIT & IN/ALL/ANY/SOME subquery' Not Supported?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template