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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

repeated records

Status
Not open for further replies.

Apprentice101

IS-IT--Management
Aug 16, 2004
66
US
hello everyone,

I have two tables, one is patients table the other one is followup patients.

I have a request to select all the patients and their latest followup.
When I run my query I have tons of records of the same patient since there is one record per patient on the patient table and many followups. Can someone please tell me if there is any SQL code or access tool to just select my all my patients and their latest follow up only?

Thanks so much!
 
Sure...Try something like this:

SELECT t1.*
FROM Patients t1
WHERE t1.Followupdate In (select top 1 t2.Followupdate from Patients t2 where t2.PatientId = t1.PatientId ORDER BY t2.Followupdate Desc);


-VJ
 
do you have a datefield in your followup table?
if so you could use Max(followup.thedate)
which would retrieve only the latest follow up.

The same could be used with an autoincremented id field in the followup table.

HTH,
fly

[blue]Typos, that don't affect the functionality of code, will not be corrected.[/blue]

Martin Serra Jr.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top