When MySQL inserts data, it removes duplicate data;

Source: Internet
Author: User

1. Use the insert ignore into statement to re-

Mysql> INSERTIGNORE intoperson_tbl (last_name, first_name) - VALUES('J','T'); Query OK,1Row affected (0.00sec) MySQL> INSERTIGNORE intoperson_tbl (last_name, first_name) - VALUES('J','T'); Query OK,0Rows Affected (0.00Sec

2. Query filtering Duplicate data

①. Using the MySQL keyword distinct to remove weight

MySQL>SELECTDISTINCT  last_name, first_name      from Person_tbl;

②. Using GROUP by to carry out the heavy

MySQL>SELECT  last_name, first_name    from  person_tbl      - GROUP  by (last_name, first_name);

3. Delete duplicate data from a table

Idea: first create a temporary table, the non-duplicated data in the temporary table, and then delete the original table, and then rename the temporary table into a formal table

MySQL>CREATETABLESELECT from person_tbl  GROUPby  (last_name, first_name, sex); MySQL>DROPTABLE  person_tbl; MySQL>ALTERTABLE to Person_tbl;

When MySQL inserts data, it removes duplicate data;

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.