Find Duplicate Entries
Moderator: General Moderators
Find Duplicate Entries
Is there any SQL command I can run to search a MySQL DB and find any duplicate entries and then print out which ones are duplicate?
Maybe there is a better solution, but this is how i would solve it for table where fields are "id" (UNIQUE), "title", "body"
Code: Select all
SELECT a.* FROM articles as a, articles as a2 where a.title = a2.title and a.body = a2.body and a.id <> a2.idJust use count() and group by the unique field and use the having clause to filter down to records with count >= 2.. somthing like this:
Code: Select all
select uniqueCol, count(*) as count from tbl_name group by uniqueCol having count >= 2- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
Should be something like:
[/quote]
Code: Select all
select uniqueCol0, uniqueCol1, uniqueCol2, count(*) as count from tbl_name group by uniqueCol, uniqueCol, uniqueCol having count >= 2