MySQL Go heavy

Source: Internet
Author: User

1, Query deduplication data

SELECT *, COUNT (distinct name) from the table group by name

2. Avoid duplication of data

If the uniqueness of a record is distinguished by a primary key primary or a unique index, it is possible to avoid duplicate insert records:

Insert ignore into table_name (EMAIL,PHONE,USER_ID) VALUES (' [email protected] ', ' 99999 ', ' 9999 '), so when there are repeated

The record will be ignored, after execution returns the number 0, there is another application is to copy the table, to avoid duplicate records:

3. Delete duplicate data and keep only one

DELETE From' Noid ' USING ' noid ',
(SELECT DISTINCT MIN(' ID ')As' id ', ' name ', 'Add`From' Noid 'GROUP By' Name ', 'Add`Having COUNT(1)> 1)As ' T2 '
WHERE ' noid '. ' name ' = ' t2 '. ' Name ' and ' noid '. 'add' = ' T2 '. 'add' and ' noid '. ' id ' <> ' T2 '. ' ID ';

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.