Remove duplicate (almost) rows based on value in the distinct column Consider this result in SQL Server: