hi dcarva, see below code..DECLARE @Input TABLE(MachineId INT,UserId INT,Hits INT)INSERT INTO @Input VALUES(1, 2, 444), (1, 4, 111), (2, 5, 365), (2, 3, 3254);WITH CTE AS(SELECT *, ROW_NUMBER() OVER (PARTITION BY MachineID ORDER BY Hits DESC) AS RnumFROM @Input)SELECT MachineID, UserID, HitsFROM CTEWHERE Rnum = 1
Read about ranking functions @ http://sqlsaga.com/sql-server/what-is-the-difference-between-rank-dense_rank-row_number-and-ntile-in-sql-server/Visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.