MySQL: esta versión de MySQL aún no admite la subconsulta 'LIMIT & IN/ALL/ANY/SOME
Este es el php
código que estoy usando.
$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
');
este es el error que me da
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
Aceptado
En lugar de usar IN, puedes usar JOIN
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
Puede utilizar lo siguiente para evitar este 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
');
No necesita una subconsulta aquí. Prueba esto:
SELECT VID, thumb
FROM video
WHERE title LIKE "%'.$Channel['name'].'%"
ORDER BY RAND() DESC
LIMIT 1
En MySQL 5.0.26 y posteriores, obtendrá un error:
MySQL no admite LIMIT en subconsultas para ciertos operadores de subconsulta:
Referencia .
agrega esta es tu condición
(SELECT * FROM (
SELECT * FROM table ORDER BY id DESC LIMIT 50
) sub
ORDER BY id ASC)