ms-accesscount

Access is multiplying my query count by 38.... why?


My data looks like


ID - InputID

If I run a query that produces the count of each data input:

SELECT First(InventoryData2.InputID) AS FirstOfInputID, Count(InventoryData2.InputID) AS InputItemCount FROM InventoryInputT, InventoryData2 GROUP BY InventoryData2.InputID HAVING (((Count(InventoryData2.InputID))>=1)); 

Which, based on the data, SHOULD provide something along the lines of


data1: 1


data2: 3


data3: 1


HOWEVER, access shows my count totals as:


data1: = 38


data2: = 114


data3 = 38


ANY IDEA WHY?


Solution

  • Because the query is producing a Cartesian product. That is, each and every row from InventoryInputT is being matched to each and every row in InventoryData2, a cross product, because the query specifies a join operation with no condition to limit which rows are to be matched with each other.

    The GROUP BY operation is collapsing the rows. Remove the GROUP BY clause and all of the aggregate functions, return just the detail rows, and you will see what's happening.