foxtrot123
Registered User.
- Local time
- Today, 01:27
- Joined
- Feb 18, 2010
- Messages
- 57
I have a junction table that stores patient visits (a patient can have 1 or more visits, and a visit type can be associated with 1 or more patients). For example:
I want to select the earliest visit (using VisitDate) for each patient, for each VisitType. For the above data, the select query should return:
I tried to do a Group By query (Group By PatientID and VisitType), and ask for the Min([VisitDate]). But I couldn't find a way to show the PtVisitID associated with the visit that gets selected. (If I include PtVisitID, I have to make it part of the Group By or derive some statistic off it, like average, etc.)
Any suggestions?
Code:
PtVisitID PatientID VisitType VisitDate
1 1 Checkup 7/1/10
2 1 Checkup 3/3/10
3 1 Wellness 5/1/10
----------------------------------------
4 2 Checkup 9/15/12
5 2 Checkup 1/10/08
etc.
Code:
PtVisitID PatientID VisitType VisitDate
2 1 Checkup 3/3/10
3 1 Wellness 5/1/10
5 2 Checkup 1/10/08
Any suggestions?