oracle__ Delete duplicate records __ Three Ways and summary (reprint Baidu Library)

Source: Internet
Author: User

Http://wenku.baidu.com/link?url=RIENeGUK4sjxe21_RBYLYHR9tbUUCmOZQRR0mIjldXLYwRAt4khDtLQD9dFyd3rz3s_ Hwlvg2oertw8sjub1r2qlqqszabo3xla8tu2qd9q

--Method 1:rowid

--Show Duplicate row select * from persons p1 where rowid<> (select Max (ROWID) from persons p2 where p1.pid=p2.pid);

Description

If you have more than one field, add it, such as: SELECT * from persons p1 where rowid<> (select Max (ROWID) from persons P2 where p1.pid=p2.pid an D p1.pname=p2.pname);

--delete duplicate row delete from persons P1 where rowid<> (select Max (ROWID) from persons p2 where p1.pid=p2.pid);

Summarize:

A: The records of each table may be the same, but the rowid of the records of each table is unique;

B: The idea of doing a problem

A: Display the maximum rowID b for the same field: Leave the record with the largest rowid of the same field, and delete the other records;

-Method Two: Group by

According to the PID group, show the number of PID more than 1 records

Select PID from Persons GROUP by PID have Count (PID) >1;

Delete duplicate rows

Delete from persons where the PID in (the Select PID from the persons Group by PID has a count (PID) >1);

This method deletes all rows with duplicate records and does not leave a burn;

--Method Three: Distinct

Cancel duplicate Row SELECT DISTINCT * from persons;

CREATE TABLE and copy "data from table with duplicate rows" created table table_new as SELECT DISTINCT * from persons;

Delete data from persons table delete from persons;

Insert data that does not have duplicate rows in the Table_new table into the persons table insert into persons select * from Table_new;

Summarize:

Use the intermediate table to import and export data to delete duplicate rows;

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.