I’m trying to select the x most “popular” records from a table where there are a number of duplicate entries. I’ve got so far as returning records based on the count of the duplicate fields, but I also need them in alphabetical order.
For example:
SELECT country, COUNT(*) TotalCount
FROM destinations
GROUP BY country
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC
LIMIT 4
This would return records as:
country – TotalCount
Mexico – 15
Cuba – 12
USA – 10
Australia – 5
How would I go about returning them ordered by country? I’ve tried changing the ORDER BY to the country field, but that then ignores the popularity, returning records with any number of duplicates.
Would a select within a select be the answer/possible?
Can’t mySQL just do this: