Oracle Lookup Duplicate Records
SELECT *
From T_info A
WHERE (SELECT COUNT (*)
From T_info
WHERE Title = a.title) > 1)
ORDER BY Title DESC
One. Find Duplicate Records
1. Find all duplicate records
SELECT * FROM table Where repeat field in (Select repeating field from table Group by repeating field having Count (*) >1)
2. Filter duplicate records (show only one)
SELECT * from Hzt Where ID in (select Max (ID) from Hzt Group by Title)
Note: A record with the largest ID is shown here
Two. Delete duplicate records
1. Delete all duplicate records (use caution)
Delete table Where Repeat field in (Select repeating field from table Group by repeating field having Count (*) >1)
2. Keep One (this should be the ^_^ that most people need)
Delete hzt Where ID. (Select Max (ID) from Hzt Group by Title)
Note: A record with the largest ID is reserved here
1, look for redundant records in the table, duplicate records are based on a single field (Peopleid) to judge
SELECT * from People
where Peopleid in (select Peopleid from People GROUP by Peopleid has count (Peopleid) > 1)
2, delete redundant records in the table, duplicate records are based on a single field (Peopleid) to judge, leaving only rowid minimal records
Delete from people
where Peopleid in (select Peopleid from People GROUP by Peopleid has count (Peopleid) > 1)
and rowID not in (select min (rowid) from people GROUP by Peopleid have Count (Peopleid) >1)
3. Find redundant records in the table (multiple fields)
SELECT * FROM Vitae a
where (A.PEOPLEID,A.SEQ) in (select Peopleid,seq from Vitae GROUP by PEOPLEID,SEQ have count (*) > 1)
4, delete redundant records in the table (multiple fields), leaving only the smallest ROWID records
Delete from Vitae a
where (A.PEOPLEID,A.SEQ) in (select Peopleid,seq from Vitae GROUP by PEOPLEID,SEQ have count (*) > 1)
and rowID not in (select min (rowid) from Vitae GROUP by PEOPLEID,SEQ have Count (*) >1)
5, look for redundant records in the table (multiple fields), does not contain the smallest ROWID records
SELECT * FROM Vitae a
where (A.PEOPLEID,A.SEQ) in (select Peopleid,seq from Vitae GROUP by PEOPLEID,SEQ have count (*) > 1)
and rowID not in (select min (rowid) from Vitae GROUP by PEOPLEID,SEQ have Count (*) >1)
Add:
There are more than two duplicate records, one is a completely duplicate record, that is, all the fields are duplicate records, the second is some key fields duplicate records, such as the Name field repeats, and other fields do not necessarily repeat or repeat can be ignored.
1, for the first repetition, easier to solve, the use of
SELECT DISTINCT * FROM tablename
You can get a result set without duplicate records.
If the table needs to delete duplicate records (1 of duplicate records are retained), you can delete them in the following ways
SELECT DISTINCT * into #Tmp tablename
DROP TABLE TableName
SELECT * INTO TableName from #Tmp
drop table #Tmp
This duplication occurs because the table is poorly designed and can be resolved by adding a unique index column.
2. This type of repetition usually requires the first record in the duplicate record to be retained, as follows
Suppose there is a duplicate field of name,address that requires a unique result set for both fields
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)
The last select gets the name,address result set (but one more autoid field, which can be written in the SELECT clause to omit this column)