clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2335598 fiddles created (27424 in the last week).

CREATE TABLE dbo.YourTable ([ID] int, [fieldA] varchar(1), [fieldB] varchar(1), [fieldC] int) ; INSERT INTO dbo.YourTable ([ID], [fieldA], [fieldB], [fieldC]) VALUES (1, 'A', 'X', 1), (2, 'A', 'X', 2), (3, 'A', 'X', 3), (4, 'A', 'Y', 4), (5, 'A', 'Y', 1), (6, 'B', 'Y', 2), (7, 'B', 'Z', 3), (8, 'B', 'Z', 4), (9, 'B', 'Z', 5) ;
9 rows affected
 hidden batch(es)


WITH CTE AS ( SELECT *, RN = ROW_NUMBER() OVER(PARTITION BY fieldA, fieldB ORDER BY fieldC DESC) FROM dbo.YourTable ) SELECT * FROM CTE WHERE RN = 1 ;
ID fieldA fieldB fieldC RN
3 A X 3 1
4 A Y 4 1
6 B Y 2 1
9 B Z 5 1
 hidden batch(es)