Given table menu, in him is column continent, for example in him is this datas
continent
----------
africa
africa
europe
europe
europe
I want get continent name, which is more times in column, that is result must be europe.
I write query, but I think my query is difficult and must be exist more ease solution for cases like this. are some ideas?
this my query
SELECT continent FROM (
SELECT continent, COUNT(continent) AS cnt FROM menu GROUP BY continent
) AS t
WHERE cnt = (
SELECT MAX(cnt) FROM (
SELECT COUNT(continent) AS cnt FROM menu GROUP BY continent
) AS t2
)
Try this:
I think you can also do it in a single query:
Regards
UPDATE:
The internal query returns the highest number of repeated items; the value is then used in the external query applied to the HAVING operator to return only items that are repeated exactly that number of time. This works in mysql, I’m not sure with other SQL dialects.