Reputation: 3142
What is the correct SQL (MYSQL) for finding the value that occurs the most?
Here's what I thought it might have been:
SELECT TOP 1 `my_field` FROM `my_table`
GROUP BY COUNT(`my_field`)
ORDER BY DESC
Upvotes: 1
Views: 545
Reputation: 29508
To get the most commonly occuring value:
SELECT `column`
FROM `table`
GROUP BY `column`
ORDER BY count(`column`) DESC
LIMIT 1
Upvotes: 2