Oracle uses rowid to delete duplicate records in a table

Source: Internet
Author: User

Oracle uses rowid to delete duplicate records in a table

 

First look at the table myemp

 

Identify records with duplicate data

 

Identify records with no duplicate data

 

Identify non-Repeated Records

 

Or

Select * From myemp e where rowid = (select max (rowid) from myemp E2 where E. userid = e2.userid and E. Username = e2.username and E. Salary = e2.salary)

 

 

How to delete duplicate data

1,
When a large amount of duplicate data exists and the column userid, username, and salary have indexes

Delete myemp where rowid not in (select max (rowid) from myemp group by userid, username, salary );

2. Suitable for the case of a small amount of duplicate data (when there is a large amount of data, the efficiency is very low)

Delete myemp e where rowid <> (select max (rowid) from myemp E2 where E. userid = e2.userid and E. Username = e2.username and E. Salary = e2.salary );

3. Exception method, suitable for the case of a large number of duplicated data

First, create an exception table.

 

Then add constraints to record errors to the table exceptions.

 

Create a temporary table for duplicate data

 

Delete all duplicate data

 

Re-insert non-duplicate data in the temporary table into the original table

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.