Hi,
I'm trying to write a query that counts the records associated with a combination of the fields Inspector and Date, but I only want it to count records that have at least one corresponding entry in another table (a junction table) linked by InspectionID. Right now, I've written this:
Code:
SELECT tbl1.InspectorID, tbl1.InspectionDate, Count(tbl1.InspectionID) AS NumberOfInspectionIDs
FROM tbl1 LEFT JOIN tbl2 ON tbl1.InspectionID = tbl2.InspectionID
GROUP BY tbl1.InspectorID, tbl1.InspectionDate
HAVING Count(tbl2.InspectionID) > 0;
But the query is returning numbers that I know can't be right. It seems to be totaling the count of records in tbl1, plus the number of records in tbl2 associated by the link.
What am I doing wrong?