Delete duplicate records in the database (add your own understanding)

Source: Internet
Author: User
ORACLE:
Delete duplicate records in the database
Select corpname, count (*) from tbcorp group by corpname having count (*)> 1
Delete from tbcorp A where a. rowid! = (Select Min (B. rowid) from tbcorp B where a. corpname = B. corpname)

The project applied to the Local Adjustment Center has the following SQL statement:
Select blockid, nodeno, count (*) from geop group by blockid, nodeno having count (*)> 1
Identify duplicate points, and use two conditions to judge...

The following is used to delete duplicate records in the database, but keep one record;

Method 1:
/* First save the unique record. SQL Server 2000 supports table changes */
Declare @ rstemp table (Code int, coderule varchar (50 ))
Insert into @ rstemp select distinct code, coderule from
/* Cancel all records */
Delete from
/* Re-insert the data */
Insert into a select * From @ rstemp

Method 2:
Delete tablename from (select PK, max (Repeat field) as K from tablename group by PK having count (*)> 1) as B, tablename where tablename. PK = B. PK and tablename. repeated Fields

This was originally an article published on my blogger , because blogger needs to be upgraded, and nnd is so annoying, you have to re-stick all the articles to upgrade. By the way, put all the technical articles here! The original Article may refer to:
http://www.cnblogs.com/wertou/archive/2006/03/29/362214.html

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.