开发者

MySQL - search for duplicates

RESOLVED! THANKS EVERYONE.

I need to search for duplicates - table as follows:

id, q1, q2, q3, text

id is unique and I am only interested in finding duplicates where the field text is the same.

Any suggestions as I have no idea where to start!

Thanks,开发者_开发问答

Homer.


This will return you duplicate values of text:

SELECT  text
FROM    mytable
GROUP BY
        text
HAVING  COUNT(*) > 1

This will return all records having duplicate values of text:

SELECT  m.*
FROM    (
        SELECT  text
        FROM    mytable
        GROUP BY
                text
        HAVING  COUNT(*) > 1
        ) q
JOIN    mytable m
ON      m.text = q.text


When I do similar things, I usually do a combination of a count query and 'having'.

for example:

select 
  text,
  count(*) as cnt
from
  table_name
group by 
  text
having cnt > 1;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜