• Skip to main content
  • Skip to primary sidebar

Ryan McCormick

How to Count by Item With SQL | Group By Query MS Access

March 6, 2014 by Ryan Leave a Comment

I also wasn’t sure how to word the title, but it seems to make sense. This is a very short post as this is pretty simple.

When reporting out on data, there is the possibility that at some point, a report request will call for a count of items by group. I wanted to make this example as simple as possible. To keep it simple, I designed a table with first names(FirstName) and location states (LocationState).

SQL Query Count Names by State

Here is the raw data:

FirstName LocationState
Jim MN
Bob MN
Kim IL
Beth WI
Sam CA
Al NY
John MN
Ryan CA
Greg NY
Sara NY
Jen CA

The Query:

SELECT LocationState, COUNT(FirstName)
FROM names
GROUP BY LocationState
ORDER BY Count(FirstName) DESC;

Results:

FirstName Expr1001
NY 3
MN 3
CA 3
WI 1
IL 1

If you want to make your results a little more fancy by adding custom column names:
NOTE: The syntax for changing column text in MS Access is to use brackets “[]”. The syntax with other database packages may use quotations. A best practice would be to search Google for the correct syntax based on your database service.

SELECT LocationState AS [Location], COUNT(FirstName) AS [Count]
FROM names
GROUP BY LocationState
ORDER BY Count(FirstName) DESC;

Results:

Location Count
NY 3
MN 3
CA 3
WI 1
IL 1

If you get stuck, comment. If this was helpful, feedback is also welcomed!

Filed Under: Microsoft Access Tagged With: Group By Query, Microsoft Access, SQL

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • Force Quit Kill all Chrome Windows MacOS
  • SOLVED: Angular 6 CLI Karma Stuck in Single Run | Karma Stops Running
  • How to Manually Install Java 8 on Ubuntu 18.04 LTS
  • Remove VirtualBox from Ubuntu 16.04 Xenial
  • Clear all Node Modules Folders Recursively Mac/Linux

Recent Comments

  1. KKV on Webstorm adding spaces between imports and braces | JavaScript and TypeScript
  2. jusopi on Clear all Node Modules Folders Recursively Mac/Linux
  3. Qaisar Irfan on Clear all Node Modules Folders Recursively Mac/Linux
  4. mustafa on Remove VirtualBox from Ubuntu 16.04 Xenial
  5. Pourya on How to Manually Install Java 8 on Ubuntu 18.04 LTS

Copyright © 2025 · Magazine Pro on Genesis Framework · WordPress · Log in