Only one entry is left for Oracle to delete duplicate data
Source: Internet
Author: User
SQL statement for querying and deleting duplicate records 1. Search for redundant duplicate records in the Table. duplicate records are determined based on a single field (ID ). Select * from table where ID in (select ID from Table group byid having count (ID)> 1) 2. Delete unnecessary duplicate records in the Table. duplicate records are determined based on a single field (ID), leaving only the records with the smallest rowid Delete from table where (ID) in (select ID from Table group by ID having count (ID)> 1) and rowid not in (select Min (rowid) from table group by ID having count (*)> 1 ); 3. Search for redundant duplicate records in the table (multiple fields) Select * from Table A where (A. ID, A. seq) in (select ID, seq from Table group by ID, seq having count (*)> 1) 4. Delete redundant record (multiple fields) in the table, leaving only the records with the smallest rowid Delete from Table A where (. ID,. SEQ) in (select ID, seq from Table group by ID, seq having count (*)> 1) and rowid not in (select Min (rowid) from Table group by ID, SEQ having count (*)> 1) 5. Search for redundant duplicate records (multiple fields) in the table, excluding records with the smallest rowid Select * from Table A where (. ID,. SEQ) in (select ID, seq from Table group by ID, seq having count (*)> 1) and rowid not in (select Min (rowid) from Table group by ID, SEQ having count (*)> 1) SQL statement for querying and deleting duplicate records 1. Search for redundant duplicate records in the Table. duplicate records are determined based on a single field (ID ). Select * from table where ID in (select ID from Table group byid having count (ID)> 1) 2. Delete unnecessary duplicate records in the Table. duplicate records are determined based on a single field (ID), leaving only the records with the smallest rowid Delete from table where (ID) in (select ID from Table group by ID having count (ID)> 1) and rowid not in (select Min (rowid) from table group by ID having count (*)> 1 ); 3. Search for redundant duplicate records in the table (multiple fields) Select * from Table A where (A. ID, A. seq) in (select ID, seq from Table group by ID, seq having count (*)> 1) 4. Delete redundant record (multiple fields) in the table, leaving only the records with the smallest rowid Delete from Table A where (. ID,. SEQ) in (select ID, seq from Table group by ID, seq having count (*)> 1) and rowid not in (select Min (rowid) from Table group by ID, SEQ having count (*)> 1) 5. Search for redundant duplicate records (multiple fields) in the table, excluding records with the smallest rowid Select * from Table A where (. ID,. SEQ) in (select ID, seq from Table group by ID, seq having count (*)> 1) and rowid not in (select Min (rowid) from Table group by ID, SEQ having count (*)> 1)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.