SQL Delete duplicate data

Source: Internet
Author: User
Tags mysql delete

SQL Delete duplicate data
This article provides a MySQL delete duplicate data, is the data table there are more than two duplicate data, delete the smallest number of a piece of information.
Delete ' Borough_name ' as a from Fke_borough as a,
(
Select *,min (ID) from Fke_borough GROUP BY ' Borough_name ' has count (1) > 1
) as B
where a. ' Borough_name ' = B. ' Borough_name ' and a.id > b.id;

SELECT COUNT (*)
From ' Fke_borough '//3423


SELECT * from ' Fke_borough ' GROUP BY ' Borough_name ' has count (' borough_name ') >1//repeat 591

Query duplicate record select * FROM table GROUP by name

Just show the repetition.
SELECT *, COUNT (*) as Nums from Tab_a Group by name has Nums>1

Method One: (This method is relatively good, only the self-added field will be rebuilt)

Create a new temporary table
CREATE TABLE tmp as SELECT * from Youtable GROUP by name
Delete the original table
drop table Youtable
Renaming tables
ALTER TABLE TMP rename Youtable

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.