ankykele
asked on
SQL query
Hello,
I am trying to write a SQL query that will return the item in a column which occurs the most. My data looks like this:
ID Country
1 US
2 UK
3 Canada
4 US
I would like my query to return the highest frequency item in the country column: US
Thanks in advance!
I am trying to write a SQL query that will return the item in a column which occurs the most. My data looks like this:
ID Country
1 US
2 UK
3 Canada
4 US
I would like my query to return the highest frequency item in the country column: US
Thanks in advance!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the query posted by Thomasian will show only one country in case of two or more countries having the highest frequency.
ASKER
Thanks alot for the solution!!!
return the highest frequency item in the country column: US
Meabns required only on record
SELECT Top 1 Country
FROM tablename
GROUP BY Country
ORDER BY COUNT(ID) DESC
Open in new window