Table A: Has field with name of species.
Table B: Has the number of specimens caught per catch.
Table C: Has measurements of specimens.
I have generated the query in design view to get the min, max, and avg length of two particular species. The query should also report the number of specimens. For some reason I am not getting the right numbers.
For example, I know for a fact that there were 84 sturgeon. If I use SUM(SpecimenCount) I get a total of 240? But if I use COUNT(SpecimenCount) I get 84.
However, in a simpler query that just reports name of species and SUM(SpecimenCount) it reports the correct number of 84.
My buddy suggested it might have something to do with the kind of join Access is using. When I look at the query in SQL view it is using an Inner Join and looks like this (sorry for the long query)
Expand|Select|Wrap|Line Numbers
- SELECT tbl_Species_Freshwater.Common_Name, Min(tbl_Specimen_Fish_Replicate.Total_Len) AS MinOfTotal_Len, Max(tbl_Specimen_Fish_Replicate.Total_Len) AS MaxOfTotal_Len, Avg(tbl_Specimen_Fish_Replicate.Total_Len) AS AvgOfTotal_Len, Min(tbl_Specimen_Fish_Replicate.Standard_Len) AS MinOfStandard_Len, Max(tbl_Specimen_Fish_Replicate.Standard_Len) AS MaxOfStandard_Len, Avg(tbl_Specimen_Fish_Replicate.Standard_Len) AS AvgOfStandard_Len, Sum(tbl_Specimen_Replicate.SpecimenCount) AS SumOfSpecimenCount
- FROM tbl_Species_Freshwater INNER JOIN (tbl_Specimen_Replicate INNER JOIN tbl_Specimen_Fish_Replicate ON tbl_Specimen_Replicate.Specimen_ID = tbl_Specimen_Fish_Replicate.Specimen_ID) ON tbl_Species_Freshwater.Species_ID = tbl_Specimen_Replicate.Species_ID
- GROUP BY tbl_Species_Freshwater.Common_Name, tbl_Species_Freshwater.Species_Code
- HAVING (((tbl_Species_Freshwater.Species_Code)="GRNSTURG" Or (tbl_Species_Freshwater.Species_Code)="WHTSTURG"))
- ORDER BY tbl_Species_Freshwater.Common_Name;
Any ideas?