1. If there is an ID field, it is a unique field
Delect table where ID not in (
Select Max (ID) from table GROUP by col1,col2,col3 ...
)
The field followed by the GROUP BY clause is the condition you use to judge the repetition, such as only col1, so that the record is the same as long as the col1 field has the same contents.
2, if you are judging all fields, you can do the same.
SELECT * into #aa from table group by Id1,id2,....
Delete Table
INSERT INTO table
SELECT * FROM #aa
3, no ID case
Select Identity (int,1,1) as id,* into #temp from tabel
Delect # where ID not in (
Select Max (ID) from # Group by col1,col2,col3 ...)
Delect table
Inset into table (...)
Select ... from #temp
4. col1+ ', ' +col2+ ', ' ... col5 Federated primary Key
SELECT * FROM table where col1+ ', ' +col2+ ', ' ... col5 in (
Select Max (col1+ ', ' +col2+ ', ' ... col5) from table
where having Count (*) >1
GROUP BY Col1,col2,col3,col4
)
The field followed by the GROUP BY clause is the condition you use to judge the repetition, such as only col1, so that the record is the same as long as the col1 field has the same contents.
5
Select Identity (int,1,1) as id,* into #temp from tabel
SELECT * from #temp where ID in (
Select Max (ID) from #emp where have count (*) >1 GROUP by col1,col2,col3 ...)
6.
SELECT DISTINCT * to #temp from TableName
Delete TableName
Go
Insert TableName SELECT * FROM #temp
Go
drop table #temp
Several ways to remove duplicate rows in MS SQL