This article provides a large number of SQL statement statements for deleting duplicate records. If you are worrying about how to delete duplicate data in the database, we provide you with a variety of SQL query statements for deleting duplicate records.
This article provides a large number of SQL statement statements for deleting duplicate records. If you are worrying about how to delete duplicate data in the database, we provide you with a variety of SQL query statements for deleting duplicate records.
SQL deletes duplicate records
This article provides a large number of SQL statements to delete duplicate records. If you are worrying about how to delete duplicate data, we provide you with a variety of SQL query statements to delete duplicate records.
Select .*
From temp a inner join (select name, sex from temp group by name, sex having count (*)> 1) B
On a. name = B. name and a. sex = B. sex
// View the instance for deleting duplicate records
// User table structure
Create table user (
Varchar (20) uname notnull;
Varchar (16) upass;
);
// Create a temporary table and copy non-duplicated data in the user table
Create table user_tmp as select distinct * from user;
Drop table user; // Delete the user table
Alert user_tmp rename user; // rename the user_tmp table to user
// ANOTHER METHOD
Delete ccs_users
Where userid in (
Select max (userid) from ccs_users group by userid having count (*)> 1)
It seems that one-person SQL deletes duplicate record instances.
For example:
Id? Name? Value
1? A? Pp
2? A? Pp
3? B? Iii
4? B? Pp
5? B? Pp
6? C? Pp
7? C? Pp
8? C? Iii
Id is the primary key.
Id? Name? Value
1? A? Pp
3? B? Iii
4? B? Pp
6? C? Pp
8? C? Iii
Method 1
Delete? Yourtable?
Where? [Id]? Not? In? (
Select? Max ([id])? From? Yourtable?
Group? By? (Name? +? Value ))
Method 2
Delete? A
From? Table? A? Left? Join (
Select? Id = min (id )? From? Table? Group? By? Name, value
) B? On? A. id = B. id
Where? B. id? Is? Null