[thelist] SQL: Select first item for each person for each day
r937
rudy at r937.com
Tue Feb 24 19:43:55 CST 2009
hi judah
try this --
SELECT appt.id
, appt.patient_id
, appt.doctor
, appt.appointment_date
FROM Appointment AS appt
INNER
JOIN ( SELECT patient_id
, MIN(appointment_date) AS first_appt
FROM Appointment
GROUP
BY patient_id
) AS firsts
ON firsts.patient_id = appt.patient_id
AND firsts.first_appt = appt.appointment_date
;o)
-------------
rudy
http://r937.com/ | http://rudy.ca/
buy my book "Simply SQL" from Amazon --
http://www.amazon.com/exec/obidos/ASIN/0980455251/
More information about the thelist
mailing list