# \[SQL\] Counting Records

**URL:** <https://forum.kirupa.com/t/sql-counting-records/223918>\
**Category:** programming\
**Created:** [April 26, 2007, 6:45pm UTC](https://forum.kirupa.com/t/sql-counting-records/223918 "2007-04-26T18:45:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Digitalosophy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/digitalosophy/32/1114_2.png) [@Digitalosophy](https://forum.kirupa.com/u/Digitalosophy)\
**Post date:** [April 26, 2007, 6:45pm UTC](https://forum.kirupa.com/t/sql-counting-records/223918/1 "2007-04-26T18:45:26Z")

</div>

Hey guys need a little help here.

My database table is set up like so

UserFileName | FirstName | LastName |UserID

Data inside is something like

Dave’s DB 1 | John | Doe | test3  
Dave’s DB 1 | Jane | Doe | test3  
Dave’s DB 4 | John | Doe | test3  
Dave’s DB 5 | John | Doe | test3

So what I need to do here is count the amount of records for all the records in this table where for example UserFileName = Dave’s DB 1

I need a count for everything in this table where the UserFileName is the same. So my end result would have a serperate count for all Dave’s DB 1 records, Dave’s DB 4 records, etc…

Dave’s DB 1 count = 2  
Dave’s DB 4 count = 1  
Dave’s DB 5 count = 1

If I use the count SQL command it’s returning the of course the total record count in the table which is incorrect. The UserFileName is variable so I can’t hard code the values in the WHERE clause. I was thinking of sticking every record with the same UserFileName in an array and just base the counting on the array length.

I’m no SQL pro - so I’m hoping there is a way of doing this in the SQL command that I just don’t know about.

Thanks yo!
