Mysql – select rows where column contains same data in more than one record

duplicationMySQL

I have a table that has a column called article_title. Let's say the table name is articles. I need to find out the records where the article_title data is the same on more than one record.

Here's what I've got:

select a.* 
from articles a 
where a.article_title = (select article_title 
                         from articles 
                         where article_title = a.article_title 
                         AND a.id <> articles.id)

Best Answer

HAVING is a great aggregate filter. (http://dev.mysql.com/doc/refman/5.6/en/group-by-extensions.html) For example, select the article_titles with more than on occurrence:

SELECT count(*), article_title
FROM articles
GROUP BY article_title
HAVING COUNT(*) > 1;

Adding columns to the SELECT and GROUP BY clauses allow you to locate duplicates based on a composite key of multiple columns.