我有两个 SQL 表:
collections(id, user_id, name)
files(id, collection_id, name, start_date)
而且我想通过一个请求检索给定用户的每个集合,每个集合具有 3 个文件(最大)的“预览”。
我的第一个(也是唯一一个)想法是这样的:
SELECT f.*
FROM collections c
LEFT JOIN files f
ON f.collection_id = c.id
WHERE c.user_id = 1 AND f.id IN
(
SELECT id
FROM files
WHERE collection_id = c.id
ORDER BY start_date DESC
LIMIT 3
)
ORDER BY c.name, f.start_date DESC
但它不适用于 MySQL,给出:
#1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
你有想法吗?=/
谢谢。