Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Query ...Interview Question ...

Author  Topic 

kraja_be
Starting Member

1 Post

Posted - 2005-04-11 : 07:19:53
Hi guys,

i need help to form this query in sql server 2000.

i have to get data from a column which is having maximum no of count

if my data is like this

Item
____

tea
tea
coffee
coffee
coffee
coffee
water
water
water

then i should get

coffee 4


Thanks in advance.

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-04-11 : 07:39:28
Select top 1 item, Cnt = count(*)
From <yourTable>
Group By item
Order By Cnt Desc

Corey

Secret Service Agent: Mr. President, you're urinating on me.
President Lyndon Johnson: I know I am. It's my prerogative.
Go to Top of Page
   

- Advertisement -