I have a patient table, a provider table and a return to work (RTW) table. Both the provider and RTW tables may have many rows for each patient, or none. I am trying to put together a select statement which will return the patient information and the most recent provider, based on begdate, and the most recent RTW episode based on lastdayworked. Following is what I would do if it were a one to one relationship. I am stumped when there are multiple children rows.
SELECT
patient.patid, patient.name,
provider.name, provider.begdate,
rtw.lastdayworked, rtw.returndate
FROM patient
LEFT JOIN provider ON provider.patid=patient.patid
LEFT JOIN rtw ON rtw.patid=patient.patid
WHERE patient.patid='123456'
TIA
Mark
SELECT
patient.patid, patient.name,
provider.name, provider.begdate,
rtw.lastdayworked, rtw.returndate
FROM patient
LEFT JOIN provider ON provider.patid=patient.patid
LEFT JOIN rtw ON rtw.patid=patient.patid
WHERE patient.patid='123456'
TIA
Mark