所以,我有2个表,release和release_favourites。
发布结构:
id date (timestamp) other data
1 1486901083 ...
2 1486909903 ...
....
release_favourites结构:
id releaseId userId
1 2 5
2 2 10
....
我想按日期排序记录(这在SQL中是没有问题的),但是我只希望最喜欢的10条记录可以吗?
(下面的SQL有效,但仅适用于按日期排序)
SELECT [some rows]
FROM release AS a, release_favourites AS b
WHERE a.id = b.releaseId
ORDER BY a.date
最佳答案
select *
from release
where id in
(
select releaseid
from release_favourites
group by releaseid
order by count(*) desc
limit 10
)
order by date
关于mysql - sql命令由另一个值限制,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42188524/