View Full Version : Count on Table Relationship


usachrisk
07-16-2002, 09:33 AM
Hello -

I'ved used SELECT COUNT(*) FROM <table> as <Field> in the past to get the count of records in a table, but I need something a little more detailed for a specific DB I'm working on.

My Setup is that I have two tables. One has account numbers, and one has a list of Employees associated with cost centers. I'm trying to get a query that will output the number of employees in each cost center as follows:

1111 : 30
2222 : 20
3333 : 00

,etc. Any thoughts?

Christopher.

Rich
07-16-2002, 09:55 AM
Use a totals query, group by account number, count employee

usachrisk
07-16-2002, 10:59 AM
Hi -

Can you be a bit more specific? I've never heard of any type of grouping in a query and help doesn't do much for me either on "Totals Query" or Grouping in a Query.

- Christopher.

Pat Hartman
07-16-2002, 11:31 AM
From what you said, it sounds like you only need to reference the employee table to get the count.

Select CostCenter, Count(*) As EmpCount
From tblEmployee
Group By CostCenter;

To create this query using the QBE grid:
1. Add the employee table
2. Select the CostCenter field
3. Press the toolbar button that looks like a backward E. This will add a new line to the grid and place the words Group By under the costcenter field
4. In the next column place -
EmpCount:Count(*)
5. Change the total line to be Expression rather than Group By