View Full Version : Counting Entries - Help Needed :)

11-09-2011, 01:02 PM
Hi Everyone,

Thanks for your help!

I have a table that has one row entry per unique event. Here's the current structure:

type varchar(1)
employee varchar(50)
routeLoaded varchar(10)
routePAL varchar(10)
address varchar(100)
comments varchar(100)
timestamp timestamp

Here are some example rows:

0 Todd 1B 1E "3016 Queso Ln" 2011-10-28 10:39:57
0 Larry 9E 7C "509 Gordita Ln" 2011-10-28 10:40:01
0 Larry 9E 7C "2087 Fiesta Ln" 2011-10-28 10:40:05
0 Matt 2B 2C "535 Taquito Ln" 2011-10-28 10:40:12
0 Matt 2B 2C "670 Burrito Ln" 2011-10-28 10:40:17
0 Matt 2B 2A "2137 Taco Ln" 2011-10-28 10:40:23

There aren't any unique fields; there are many entries with the same employee, address, etc.

What I want to do is display a count of how many entries in this table each employee has.

So, for the example above, the result I want is:

Matt 3
Larry 2
Todd 1

I had expected to be able to use Count, but as far as I can tell I can't do what I want with Count in my query.

Thanks for your help,

11-09-2011, 06:00 PM
show us what you have tried and why you think count won't work.

11-09-2011, 08:55 PM
select count(*) from table_name where column='whatyouwantcounted';

There ya go.

Old Pedant
11-09-2011, 09:09 PM
SELECT employee, COUNT(*) as recordsPerEmployee
FROM tablename
GROUP BY employee
ORDER BY employee

Or you could do

ORDER BY recordsPerEmployee DESC

or or or...but the important part is the GROUP BY.