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!
ankykeleAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ThomasianCommented:
SELECT TOP 1 Country
FROM tablename
GROUP BY Country
ORDER BY COUNT(1) DESC

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mayank_joshiCommented:
with cte as
(
select country,count(ID) as cnt from tblcounty group by country )

select * from cte where cnt=(Select max(cnt) from cte);

Open in new window

0
mayank_joshiCommented:
the query posted by Thomasian will show only one country in case of two or more countries having the highest frequency.
0
ankykeleAuthor Commented:
Thanks alot for the solution!!!
0
Pratima PharandeCommented:

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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.