MySQL Go heavy

Source: Internet
Author: User
Tags uuid

There are two ways to use it:

1. Single Statement method:

1) Delete b from Sys_test B, (select *,max (UUID) from Sys_test Group BY ' name ' have count (' name ') > 1) as D where B.uu Id>d.uuid and b.name = D.name

Delete b from Sys_test B is a set alias, the DELETE statement is generally directly connected to the from, when the need to set the from table alias is, the alias needs to be placed before the from, indicating that the deletion is the content of the alias is deleted.

From the different tables used, split, can have sub-query out of the table, followed by where can.

2) Delete form user where ID not in (the Select ID from (select Max (ID) as ID, name, social Security number from the user group by name, Social Security number) as T);

The method is slightly less efficient

2. Temporary table method

1), find all duplicate data, and copy the duplicate data to a temporary table

SELECT * into #temp1 from the user group by ' name ' have count (' name ') > 1

2), delete all duplicate data from the original table

Delete from the user where name in (the Select ' name ' from the user group by ' name ' has count (' name ') > 1);

3), insert the data from the staging table back into the user table

INSERT INTO user select * from #temp1;

4), delete temporary table

Drop #temp1;

MySQL Go heavy

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.