MySQL - LIMIT & IN/ALL/ANY/SOME subquery is not currently supported in this version of MySQL
P粉316423089
P粉316423089 2023-10-16 22:44:50
0
2
563

This is the php code I am using

$Last_Video         = $db->fetch_all('
    SELECT VID, thumb
    FROM video
    WHERE VID IN (
        SELECT VID
        FROM video
        WHERE title LIKE "%'.$Channel['name'].'%"
        ORDER BY viewtime DESC
        LIMIT 5)
    ORDER BY RAND()
    LIMIT 1
');

This is the error it gives me

Message:   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<br />
 MySQL Error:   This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'<br />
MySQL Errno:    1235


P粉316423089
P粉316423089

reply all(2)
P粉702946921

You can use the following methods to bypass this error.

$Last_Video = $db->fetch_all('
    SELECT VID, thumb
    FROM video
    WHERE VID IN (select * from (
        SELECT VID
        FROM video
        WHERE title LIKE "%'.$Channel['name'].'%"
        ORDER BY viewtime DESC
        LIMIT 5) temp_tab)
    ORDER BY RAND()
    LIMIT 1
');
P粉283559033

You can use JOIN instead of IN

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!