MySQL Delete duplicate data

Source: Internet
Author: User

Delete from co_jobinformation C
where C.name in (select Cc.name from Co_jobinformation cc GROUP BY Cc.name have count (cc.name) > 1)
and rowID not in (select min (rowid) from Co_jobinformation e Group by E.name have Count (e.name) >1)

Previously in the Oracle database can delete duplicate data and can keep a unique data, but the same MySQL does not,

MySQL has a feature, to modify the table, delete the operation, the subquery can not be the same as the outer query table, so the addition of a select can be

DELETE tt.*
From T_user TT--This is the table of operations
WHERE Tt.username--This is the duplicate user name data
In (
SELECT Cc.username
From (
SELECT b.*
From T_user b
) cc
GROUP by Cc.username
Having COUNT (cc.username) >1
)
and Tt.id--here is the smallest reservation ID, it should be easier to read.
Not IN (
SELECT MIN (e.id)
From (
SELECT ee.*
From T_user ee) E
GROUP by E.username
Having COUNT (e.username) >1)
)
)

I write a little ugly, but I want the results achieved, that is, the above sub-query inside the table for select query, but also master left high-quality SQL, thank you!

MySQL Delete duplicate data

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.