I'm not 100% how the other fields come into play ("B@" and "Ref@") but, maybe this will help?SELECT T."Polref@", T."Suffix@" AS 'Max of Suffix@' Daprospect.Doc_typeFROM Opengi.dbo.Daprospect AS DaprospectINNER JOIN ( SELECT "Polref@", "Suffix@", "B@", "Ref@", ROW_NUMBER() OVER (PARTITION BY "Polref@" ORDER BY "Suffix@" DESC) AS RowNum FROM Opengi.dbo.Dadiary ) AS T ON T."B@" = Daprospect."B@" AND T."Ref@" = Daprospect."Ref@" WHERE RowNum = 1 AND ((Daprospect."Source#" In ('Spa MULTI','Spa TRANSFERRED')))ORDER BY T."Polref@"PS: This could probably also be done by doing the GROUP BY as a query in a derived table and using that to join to or using CROSS APPLY.EDIT: Forgot ORDER BY.