SELECT * FROM(SELECT *,ROW_NUMBER() OVER(PARTITION BY UserName ORDER BY Id DESC) Num FROM dbo.[User] ) t WHERE t.Num=1