SQL removal of duplicate data

Source: Internet
Author: User

1. Add test data with stored procedures

CREATE PROCEDURE newprocedure ()
BEGIN
DECLARE i INT;
SET I=1;
While i<50000 do
INSERT into User_new (id,name,phone,sex) VALUES (i,i,i,i);
SET i = i + 1;
END while;
END;

Two inserts, modifies the ID value of the stored procedure once, then obtains the Name,phone,sex duplicate 5W data (time is limited, does not operate the larger quantity)

2, Data de-weight

Common ways:

One

Update user_new set data_status=0 where ID not in

(select Max (ID) as ID from t_testr_res_indicate GROUP by Name,phone,sex
);

Second, the volume of repeated data use less

Update user_new set data_status=0 where ID not in

(select Max (ID) as ID from user_new GROUP by Name,phone,sex have Count (*) >1
) and

ID in

(select ID from user_new GROUP by Name,phone,sex have Count (*) >1
) ;

SQL removal of duplicate data

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.