MySQL-这个版本的 MySQL 还不支持“ LIMIT & IN/ALL/ANY/SOME 子查询”

这是我使用的代码

    $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
');

这就是给我的错误

 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

我怎样才能解决这个问题?它的另一种方式使它... 所以我不会得到错误..。

107994 次浏览

这里不需要子查询,试试这个:

 SELECT VID, thumb
FROM video
WHERE title LIKE "%'.$Channel['name'].'%"
ORDER BY RAND() DESC
LIMIT 1

在 MySQL 5.0.26及更高版本中,您将看到一个错误:

对于某些子查询操作符,MySQL 在子查询中不支持 LIMIT:

参考

您可以使用 JOIN 代替 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

为什么你不能使用简单的: ?

SELECT v.VID, v.thumb
FROM video as v
WHERE title LIKE "%'.$Channel['name'].'%"
ORDER BY viewtime DESC
LIMIT 5

这里的子查询是什么?

您可以使用以下方法绕过此错误。

$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
');

加上这是你的条件

(SELECT * FROM (
SELECT * FROM table ORDER BY id DESC LIMIT 50
) sub
ORDER BY id ASC)

Mysql 被禁用 读吧,甲骨文

DELETE FROM wall _ orders WHERE order _ id IN (
SELECT ORDER _ id FROM (SELECT ORDER _ id,COUNT (orders _ products _ id) as cnt FROM wall_orders_products GROUP BY ORDER _ id ORDBY cnt DESC LIMIT 1000) y1 WHERE cnt > 170 LIMIT 1000)

235-这个版本的 MariaDB 还不支持“ LIMIT & IN/ALL/ANY/SOME 子查询”

简单的 SQL,不可能