View Full Version : How To Do A Count In SQL Of THe Most Common Item


Noob2008
11-02-2009, 04:27 PM
Hi ,

I Have A database table call Department . In this table imagine this , everyday i have to enter a department for a month . Department i enter can have repeated entires (For examples : there can be 1 or more particular department in a month)

Department <---- Column Name
Logistics
F&B
Administrator
Logistics
Logistics
ETC .... till 30 records ( Taking into account that particular month has 30 days )

Now my Q is is there a SQL statement in which i can run it and it will count and tell me which is the department that has the most re-Occurance ?

In my example above it shld returm Logistics as it appear 3 times .

Kindly Advise . Thanks

pbaldy
11-02-2009, 04:32 PM
Try this untested SQL

SELECT Top 1 Department, Count(Department) AS HowMany
FROM TableName
GROUP BY Department
ORDER BY Count(Department) DESC;

Noob2008
11-02-2009, 04:46 PM
Great ! It Works Nice .

Thanks ! Much ! :) :p:p

pbaldy
11-02-2009, 04:52 PM
No problemo, and welcome to the site by the way!

Noob2008
11-02-2009, 08:07 PM
:p:D:p . Thanks :)