;WITH cte AS( SELECT *, ROW_NUMBER() OVER (PARTITION BY ProductCode ORDER BY Id DESC) AS rn FROM ProductPriceInfo)SELECT *FROM cteWHERE rn = 1