0

In a table, I want to return duplicate rows based on three columns and a count of the duplicates found.

For example, In a row, say I have an entry of 1 for column a, 1 for column b and 1 for column c. I only want to return/count this row if other rows have the exact same entry for the 3 columns (1, 1 and 1).

Thanks in advance! -N

Neykho
  • 37
  • 6
  • Possible duplicate question: http://stackoverflow.com/questions/854128/find-duplicate-records-in-mysql – JohnP Jun 27 '12 at 16:19

1 Answers1

2
-- You need to specify the columns you need, and the count
SELECT   col1, col2, col3, COUNT(*)
FROM     myTable
-- Then you have to group the tuples based on the columns you are doing the count on
GROUP BY col1, col2, col3
-- Here you specify the condition for COUNT(*)
HAVING   COUNT(*) > 1;

You can find more information about this here (plus some other useful stuff).

Radix
  • 1,317
  • 2
  • 17
  • 32