MyTable ----------- RowID int not null identity(1,1) primary key, Col1 varchar(20) not null, Col2 varchar(2048) not null, Col3 tinyint not null
精华回答 假设没有null值,你可以先对其他列做group by,然后只保留MIN或者MAX(RowId),删除其他行:
如果RowId不是int类型,而是个GUID,则可以用DELETE MyTable FROM MyTable LEFT OUTER JOIN ( SELECT MIN(RowId) as RowId, Col1, Col2, Col3 FROM MyTable GROUP BY Col1, Col2, Col3 ) as KeepRows ON MyTable.RowId = KeepRows.RowId WHERE KeepRows.RowId IS NULL
CONVERT(uniqueidentifier, MIN(CONVERT(char(36), MyGuidColumn)))