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