[ExactReplica].[FilteredOpportunityProduct] Table
Opportunityid baseamount
1 500
1 500
2 600
2 700
[ExactReplica].FilteredOpportunity Table
Opportunityid name
1 ABC
2 CDF
I want to take the maximum baseamount; however, am facing issue when there exists duplicate of the baseamount, how can I take only one record
My Query
select
MaxAmount.[baseamount] ,
c.name
FROM [ExactReplica].FilteredOpportunity c
Left JOIN
(
SELECT opportunityid,
MAX((baseamount)) baseamount
FROM [ExactReplica].[FilteredOpportunityProduct]
GROUP BY opportunityid
) MaxAmount ON c.opportunityid = MaxAmount.opportunityid
inner JOIN
[ExactReplica].[FilteredOpportunityProduct] p ON MaxAmount.opportunityid = p.opportunityid
AND MaxAmount.baseamount = p.baseamount
Try this:
OUTPUT: