We can use the keyword distinct to remove duplicate elements in the result set, but this does not delete repeated elements in the database.
If you want to delete data with repeated fields in a data table, it is a good way to use a temporary table as a transfer station.
Suppose we want to delete extra rows of data with duplicate values in blogurl fields in the data table tb_blogs (only one row of data with the same blogurl is retained), then we can do this:
Select * into # temp1 from tb_blogs where ID in (select max (ID) from tb_blogs group by blogurl)
This statement saves all the data that has not been duplicated to the temporary table # temp1 (note that my table has a primary key ID. If there is no primary key row, you should create a primary key in the temporary table, then, duplicate rows in the temporary table, and create another temporary table to save data without duplicate rows.) then
Drop table tb_blogs
Delete table tb_blogs
Select * into tb_blogs from # temp1
Reverse all data in the temporary table that does not have duplicate rows to tb_blogs.
Drop table # temp1
Delete temporary table
When I thought the above was a good method, the spider made me feel confused, and there was a better way:
Delete from tb_blogs where [ID] Not in (select max ([ID]) from tb_blogs group by [blogurl])