View Full Version : Returning correct results


popen
11-12-2001, 02:57 AM
I have a table of patient details with some that will appear more than once.
I need a query that will only bring back those that appear more than once, and show the results in the relating report.

A normal SELECT statement I have used to filter the results brings back ALL of the patients from the table, which I would expect. But I am stuck on where to only bring those back that appear more than once.

Thanks in advance if you can help me.

popen
11-12-2001, 04:24 AM
OK, I'm half way there. I have used the following statement;

SELECT DISTINCT [rptQAB - Temp].PatientID, [rptQAB - Temp].AttendanceID
FROM [rptQAB - Temp]
WHERE ((([rptQAB - Temp].PatientID) In (SELECT [PatientID] FROM [rptQAB - Temp] As Tmp GROUP BY [PatientID] HAVING Count(*) >1 )))
ORDER BY [rptQAB - Temp].PatientID;

Which works OK, but it brings back ALL the duplicates, I only want to see each Patient ID once that has been duplicated.

Thanks in anticipation.

diversoln
11-12-2001, 08:57 AM
Now run a second query to provide unique results.