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;
精彩评论