Delete duplicate records (MySQL) under a specific impact factor (field column)

Source: Internet
Author: User

;CREATE TABLEtabtest (' id 'INT( One) not NULLauto_increment, ' Factora 'VARCHAR(255) not NULL DEFAULT ' ', ' Factorb 'VARCHAR(255) not NULL DEFAULT ' ', ' Factorc 'DECIMAL(Ten,2) not NULL DEFAULT 0, ' remark 'VARCHAR(255) not NULL DEFAULT ' '    , PRIMARY KEY(' id ')) ENGINE=INNODB auto_increment=0 DEFAULTCHARSET=UTF8 COMMENT="';INSERT  intotabtest (Factora, Factorb, FACTORC, remark)SELECT 'A1','B1',0.5,'1..'UNION  All SELECT 'A1','B1',0.5,'2..'UNION  All SELECT 'A2','B2',0.5,'3..'UNION  All SELECT 'A2','B2',1.5,'4..'UNION  All SELECT 'A2','B2',0.5,'5..';SELECT *  fromTabtest;

-- programme I ; DELETE  from WHERE  not inch SELECT *  from SELECT  from GROUP  by Factora, Factorb, FACTORC) b);
--Scenario TwoDELETE  fromTabtestWHEREIdinch (    --MySQL Error 1093–can ' t specify target table for update on FROM clause    SELECTb.ID from     (        SELECTTouter. ' ID ' fromtabtest TouterINNER JOIN         (            SELECTtinner.id, Tinner.factora, Tinner.factorb, Tinner.factorc fromtabtest TinnerGROUP  byTinner.factora, Tinner.factorb, Tinner.factorc having COUNT(1)> 1) A onTouter. ' Factora '=A. ' Factora ' andTouter. ' Factorb '=A. ' Factorb ' andTouter. ' Factorc '=A. ' Factorc 'WHERETouter. ' ID '<>A. ' id ') b)

Plan One: data volume hours, more convenient

Scenario Two: when the data volume is large, the first scheme is tested under 700,000 data, 5 minutes out of the results, discard, use the second scheme, the second end.

Delete duplicate records (MySQL) under a specific impact factor (field column)

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.