CREATE TABLE [TestTable] ( [uid] nvarchar(10) NOT NULL , [key] nvarchar(10) NOT NULL , [value] decimal(10) NOT NULL DEFAULT ((0))) GO ALTER TABLE [TestTable] ADD PRIMARY KEY ([uid], [key]) GO INSERT INTO [dbo].[TestTable] ([uid], [key], [value]) values ('101', 'c1', 11) GO INSERT INTO [dbo].[TestTable] ([uid], [key], [value]) values ('101', 'c2', 12) GO INSERT INTO [dbo].[TestTable] ([uid], [key], [value]) values ('101', 'c3', 13) GO INSERT INTO [dbo].[TestTable] ([uid], [key], [value]) values ('102', 'c1', 21) GO INSERT INTO [dbo].[TestTable] ([uid], [key], [value]) values ('102', 'c2', 22) GO INSERT INTO [dbo].[TestTable] ([uid], [key], [value]) values ('102', 'c3', 23) GO WITH cte AS ( SELECT *, ROW_NUMBER() OVER (PARTITION BY uid ORDER BY [key] DESC) AS rn FROM vtable ) SELECT * FROM cte WHERE rn = 1