我想在LIMIT
中的子查询中使用MySQL
,但每次运行查询时都会出现[42000][1235] This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME sub query'
错误。
我正在尝试仅获取从子查询返回的第一个20
ID。
SELECT c.collection_name, t.raw
FROM collections c
JOIN member_of_collection m
ON c.collection_id = m.collection_id
JOIN citations t
ON m.citation_id = t.citation_id
WHERE m.collection_id IN
(
SELECT count(*) FROM collections c
JOIN member_of_collection m
ON c.collection_id = m.collection_id
JOIN citations t
ON t.citation_id = m.citation_id
WHERE length(trim(t.raw)) > 0
AND RIGHT(c.collection_name, length(c.collection_name) - 4) IN (SELECT cat_name from cats_cat)
AND left(t.raw, 3) != '–––'
GROUP BY c.collection_name
ORDER BY count(*) desc
LIMIT 20
);
答案 0 :(得分:1)
您可以使用join
:
SELECT c.collection_name, t.raw
FROM collections c JOIN
member_of_collection m
ON c.collection_id = m.collection_id JOIn
citations t
ON m.citation_id = t.citation_id JOIN
(SELECT c.collection_id, count(*)
FROM collections c JOIN
member_of_collection m
ON c.collection_id = m.collection_id JOIN
citations t
ON t.citation_id = m.citation_id
WHERE length(trim(t.raw)) > 0 AND
RIGHT(c.collection_name, length(c.collection_name) - 4) IN (SELECT cat_name from cats_cat)
AND left(t.raw, 3) != '–––'
GROUP BY c.collection_id
ORDER BY count(*) desc
LIMIT 20
) cc
ON m.collection_id = cc.collection_id;
这有几个假设:
collection_id
与 collection_id 进行比较,而非计数。