This is a followup to my question 700541 in the Excel forum, where HansV wisely recommended I turn to Access instead. Having done so, I’m now asking how to tailor my query results to avoid duplicates in one particular field (DISTINCT seems to look for unique records instead).
The scenario: Imagine a group of clinics (units) collaborating on medical studies. Study participants visit the clinics for their medical procedures. At a given clinic (identified by a unitID number) I want to count the first 20 distinct participants to complete a clinic visit on or after January 1, 2007.
Here is the SQL code I have, using an example unitID:
SELECT TOP 20 tblVisits.unitID, tblVisits.protocol, tblVisits.ParticipantID, tblVisits.EnrollmentDate, tblVisits.CompletedVisitDate, tblVisits.Visit
FROM tblVisits
WHERE (((tblVisits.unitID)=”45601″) AND ((tblVisits.CompletedVisitDate)>=#1/1/2007#))
ORDER BY tblVisits.CompletedVisitDate;
…but I think this will not prevent duplicates in the ParticipantID field. That is, 1 participant may have a second visit before 19 others have had their first.
How can I get the query to return the first 20 records (chronologically) but only after skipping those records whose ParticipantID has already occurred?
Thanks in advance,
Erik
P.S. I’ve included the fields “protocol” and “EnrollmentDate” because they will be needed later, but they are not relevant to this particular query.
P.P.S. The next step is, I’ll want to do the same thing for all clinics: the first 20 unique participants at EACH clinic.