Trouver tous les enregistrements avec des titres en double :
SELECT * FROM t_info a WHERE ((SELECT COUNT(*) FROM t_info WHERE Title = a.Title) > 1) ORDER BY Title DESC
1. Rechercher les enregistrements en double
1. Rechercher tous les enregistrements en double
Select * From 表 Where 重复字段 In (Select 重复字段 From 表 Group By 重复字段 Having Count(*)>1)
2. (Un seul est affiché)
Select * From HZT Where ID In (Select Max(ID) From HZT Group By Title)
Remarque : l'enregistrement avec le plus grand identifiant est affiché ici
2. Supprimer les enregistrements en double
🎜>Delete 表 Where 重复字段 In (Select 重复字段 From 表 Group By 重复字段 Having Count(*)>1)
Delete HZT Where ID Not In (Select Max(ID) From HZT Group By Title)
3. Exemples
select * from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
delete from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1) and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)
select * from vitae a where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
delete from vitae a where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1) and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
select * from vitae a where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId, seq having count(*) > 1) and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
4. Supplémentaire
select distinct * from tableName
select distinct * into #Tmp from tableName drop table tableName select * into tableName from #Tmp drop table #Tmp
La raison de cette duplication est une mauvaise conception de la table. Il est possible d'ajouter une colonne d'index unique. résolu.
select identity(int,1,1) as autoID, * into #Tmp from tableName select min(autoID) as autoID into #Tmp2 from #Tmp group by Name,autoID select * from #Tmp where autoID in(select autoID from #tmp2)
Ce qui précède est le contenu de MySQL - une méthode complète d'interrogation des enregistrements en double et de suppression des enregistrements en double. Pour plus de contenu connexe, veuillez faire attention au site Web PHP chinois (www.php. .cn) !