View Full Version : Querie count??


brin
03-01-2002, 01:50 AM
I am trying to do the following but the counts i am getting are bizzare???
SELECT [Error Log].[Welcome Pack Status], [Staff List].Region, Count([Staff List].Region) AS CountOfRegion
FROM [Staff List], [Error Log]
GROUP BY [Error Log].[Welcome Pack Status], [Staff List].Region;

I only have the two tables, i am trying to do the count using fields from both of them i think this has something to do with it???

RV
03-01-2002, 02:58 AM
You'll need to join the tables in your query.
Say ID is your Primary Key field for [Staff List] and the Foreign Key for your table [Error Log], your statement would be:

SELECT [Error Log].[Welcome Pack Status], [Staff List].Region, Count([Staff List].Region) AS CountOfRegion
FROM [Staff List] INNER JOIN [Error Log] ON
[Staff List].ID=[Error Log].ID
GROUP BY [Error Log].[Welcome Pack Status], [Staff List].Region;

Now you're getting a so-called carthesian products (all possible combinations between your two tables).

Suc6,

RV

brin
03-01-2002, 04:10 AM
Thanks. But this doesn't seem to work??? Any other ideas??

Pat Hartman
03-01-2002, 05:31 AM
RV just guessed at what the proper join field would be. Make sure you use the correct one.

I prefer to use the Count(*) syntax rather than Count(somefieldname) because if there is an appropriate index, Jet never has to read the base table which makes the query more efficient. The other difference is that Count(*) will count null values should there be any whereas Count(somefield) will not.