Processing of duplicate data in a table

Source: Internet
Author: User
The SQL statement for querying and deleting duplicate data MySQL query columnName contains duplicate data, and the largest id is retained. SELECTMAX (id) ASid, columnName, COUNT (columnName) AScountNumberFROMtableNameGROUPBYcolumnNameHAVINGcountNumber1ORDERBYcountNumberDESC; Delete colum

The SQL statement for querying and deleting duplicate data MySQL query columnName contains duplicate data, and the largest id is retained. Select max (id) AS id, columnName, COUNT (columnName) AS countNumberFROM tableNameGROUP BY columnNameHAVING countNumber 1 order by countNumber DESC; Delete colum

SQL statement for querying and deleting duplicate data MySQL
Query repeated data in columnName and retain the largest id. Select max (id) AS id, columnName, COUNT (columnName) AS countNumberFROM tableNameGROUP BY columnNameHAVING countNumber> 1 order by countNumber DESC; Delete repeated columnName data and retain the smallest id. DELETE tableName t1FROM tableName t1, (SELECT min (id) id, columnName FROM tableName group by columnName having count (1)> 1) t2WHERE t1.columnName = t2.columnNameAND t1. id> t2.id;

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.