problemSuppose you have a table with a larger amount of data (for example, 300,000+ rows), where there are duplicate rows (other than the primary key, the other column data is the same), how do you quickly go heavy? My watch looks like this.
MyTable-----------RowID int not null identity(1,1) primary key,Col1 varchar(20) not null,Col2 varchar(2048) not null,Col3 tinyint not null
Essence AnswerAssuming there are no null values, you can first group by the other columns, and then only Min or Max (RowId), to delete the other rows:
DELETE MyTable FROM MyTableLEFT OUTER JOIN ( SELECT MIN(RowId) as RowId, Col1, Col2, Col3 FROM MyTable GROUP BY Col1, Col2, Col3) as KeepRows ON MyTable.RowId = KeepRows.RowIdWHERE KeepRows.RowId IS NULL
If ROWID is not of type int, but is a GUID, you can use the
StackOverflow Link: http://stackoverflow.com/questions/18932/how-can-i-remove-duplicate-rows
"StackOverflow problem Selection" in SQL to remove duplicate rows