Dear Code masters,
I believe this mail meet you all in good health, i am writting an SQL script that will generate all patient and their most current LastDrugPickupDate. my script is as below
- SELECT Distinct a.Ptn_Pk, a.PatientEnrollmentID AS PatientID,
- CONVERT(datetime, a.ARTStartDate, 103) AS ARTStartDate, CONVERT(datetime, c.DispensedByDate, 103) AS LastDrugPickup
- ,b.Duration,b.RegimenType, c.RegimenLine FROM dbo.VW_PatientDetail AS a left JOIN
- dbo.VW_PatientPharmacy AS b ON a.Ptn_Pk = b.Ptn_pk left JOIN
- dbo.ord_PatientPharmacyOrder AS c ON b.ptn_pk = c.ptn_pk
- WHERE a.ARTStartDate IS NOT NULL And b.RegimenType is not NULL
- ORDER BY c.DispensedByDate desc
the result is show below with alot of duplicate rows:
Please how can i remove the duplicate rows but retaining the most current LastDrugPickDate looking at the yellow shaded records.thank you


Midhun TpRank #388 · 6.5K reputationPosted Apr 21, 2017, 1:05 AM EDT
Joseph ThomasRank #1,536 · 1K reputationPosted Apr 19, 2017, 8:52 PM EDT
Abraham OlatubosunRank #2,749 · 510 reputationPosted Apr 19, 2017, 9:11 PM EDT
Rafnas T PRank #280 · 8.8K reputationPosted Apr 19, 2017, 11:37 PM EDT
Abraham OlatubosunRank #2,749 · 510 reputationPosted Apr 20, 2017, 1:54 AM EDT
Rafnas T PRank #280 · 8.8K reputationPosted Apr 20, 2017, 2:03 AM EDT
Rafnas T PRank #280 · 8.8K reputationPosted Apr 20, 2017, 11:03 PM EDT
Ramesh BarikRank #3,664 · 401 reputationPosted Apr 22, 2017, 8:33 AM EDT