SELECT FIRSTNAME,LASTNAME,LASTFILLEDDATE
FROM
(
SELECT MEM.FIRSTNAME,MEM.LASTNAME,POD.LASTFILLEDDATE,
RN=ROW_NUMBER() over (PARTITION BY MEM.MEMBERID ORDER BY PO.PHARMACYORDERID DESC, POD.LASTFILLEDDATE DESC)
FROM PHARMACYORDERDETAILS POD
INNER JOIN PHARMACYORDERS PO
ON PO.PHARMACYORDERID = POD.PHARMACYORDERID
INNER JOIN MEMBERS MEM
ON MEM.MEMBERID = PO.MEMBERID
) SQ
WHERE RN=1
|