开发者

Optimizing a MySQL query that finds duplicate data

I have a query that I use for finding duplicate data. I have found that lately the query is very slow, and only getting slower. This is the query I am using (columns renamed):

  SELECT col1, 
         COUNT(col1) AS Counter 
    FROM people 
GROUP BY col1 
  HAVING (Counter > 1)

I have indexed col1 (which is a varchar(500)), but the query takes a开发者_C百科n epic amount of time to execute. Is there a better way to handle this, or am I stuck?


Try this:

SELECT  *
FROM    people po
WHERE   EXISTS
        (
        SELECT  NULL
        FROM    people pi
        WHERE   pi.col1 = po.col1
        LIMIT 1, 1
        )

This will return you each duplicated instance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜