I want to select the top 5 most frequent albums from a database, using this database: http://www.sqlitetutorial.net/tryit/query/sqlite-inner-join/#3
with this query:
SELECT
albums.title AS Album,
artists.name AS Artist,
COUNT(albums.title ) as TitleCount
FROM tracks
INNER JOIN albums ON albums.albumid = tracks.albumid
INNER JOIN artists ON artists.artistid = albums.artistid
GROUP BY
albums.albumid
ORDER BY
TitleCount DESC
Limit 5 is not a good solution, as in my case, there are 2 albums with 25 titles, what I want is the top 5 by titleCount value. It seems like limit doesn't take COUNT, but integers
expected result:
|Album |Artist |TitleCount|
|Greatest Hits |Lenny Kravitz|57 |
|Minha Historia |Chico Buarque|34 |
|Unplugged |Eric Clapton |30 |
|Lost, Season 3 |Lost |26 |
|Lost, Season 1 |Lost |25 |
|The Office, Season 3|The Office |25 |
ps: this might be a duplicate of SQL - Most frequent value in column of joined tables, but I can't apply it to mine