Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count Unique Records in Query

Status
Not open for further replies.

SimRick

Technical User
May 2, 2001
21
US
I have the following query:
Code:
SELECT tblreport.[Resident Involved 1], tblreport.[Report Number], tblreport.[Report Date]
FROM tblreport
GROUP BY tblreport.[Resident Involved 1], tblreport.[Report Number], tblreport.[Report Date]
HAVING (((tblreport.[Report Date]) Between Date() And Date()-30));
I need to display those records where a unique [Resident Involved 1) has three or more records returned in the query. Can anyone help?
Thanks
 
SELECT tblreport.[Resident Involved 1], tblreport.[Report Number], tblreport.[Report Date]
FROM tblreport
WHERE (((tblreport.[Report Date]) Between Date() And Date()-30));
GROUP BY tblreport.[Resident Involved 1], tblreport.[Report Number], tblreport.[Report Date]
HAVING Count([Resident Involved 1]) > 2


Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual
 
pressed submit too soon:

SELECT tblreport.[Resident Involved 1], tblreport.[Report Number], tblreport.[Report Date]
FROM tblreport
WHERE tblreport.[Report Date] Between Date() And (Date()-30)
GROUP BY tblreport.[Resident Involved 1], tblreport.[Report Number], tblreport.[Report Date]
HAVING Count([Resident Involved 1]) > 2



Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual
 
Thanks, but it didn't work. it should return 1 [Resident Involved 1] who had 3 reports, but didn't return any.
 
And this ?
SELECT A.[Resident Involved 1], A.[Report Number], A.[Report Date]
FROM tblreport AS A INNER JOIN (
SELECT [Resident Involved 1] FROM tblreport
WHERE [Report Date] Between Date() And (Date()-30)
GROUP BY tblreport.[Resident Involved 1] HAVING Count(*)>2
) AS B ON A.[Resident Involved 1] = B.[Resident Involved 1]
WHERE A.[Report Date] Between Date() And (Date()-30);

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Perfect, Thanks a lot. This forum is irreplaceable!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top