troubleshooting Question

Selecting one row to eliminate duplicates. The goal is to return a single row with the max(GiftAmount) regardless if there are multiple records with the same GiftAmount

Avatar of ajdajd
ajdajdFlag for United States of America asked on
Microsoft SQL Server
1 Comment1 Solution12 ViewsLast Modified:
I'm having issues trying to select one row for each DonorConstituentID when more than one row exists with the same DonorConstituentID, DonorAmount and GiftDate.  I've tried TOP and RANK but can't seem to select just one of the rows where the three fields are the same.

With CTE as (Select g.DonorConstituentID, g.DonorAmount, GiftDate, APPEAL_ID, CAMPAIGN_ID, FUND_ID
From tblCCGiftsSoftCredit as g)
Select a.DonorConstituentID,  a.DonorAmount, a.GiftDate, APPEAL_ID, CAMPAIGN_ID, FUND_ID
(Select DonorConstituentID, Max(DonorAmount) as LargestGift, Min(Giftdate) as FirstGiftDate
from CTE
Group by DonorConstituentID) L LEFT JOIN CTE A ON  A.DonorConstituentID=L.DonorconstituentID and a.DonorAmount=L.LargestGift and A.GiftDate=L.FirstGiftDate
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros