Jump to content

Opposite of DISTINCT without Group By


sw9

Recommended Posts

I have a table with many columns, including: group_id, contact_id

It has 20,000 rows in it. I cannot have entries where group_id and contact_id are the same more than once, so for example:

 

group_id  |    contact_id

100                606

100                606

 

Are bad. But

 

group_id  |  contact_id

100              606

68                606

 

are fine. I need to find instances where they are duplicate entries. If I run this query:


SELECT DISTINCT group_id, contact_id
FROM table1
GROUP BY group_id, contact_id

then I believe it's showing me how many are distinct, and that leaves me to believe that there are about 400 cases of duplicates. I need to see all the ones that are duplicates. How do I write this query?

Link to comment
https://forums.phpfreaks.com/topic/202949-opposite-of-distinct-without-group-by/
Share on other sites

thanks for that suggestion. there had to be a dupe of the same table to really get what was needed. i ended up using this query:

 

SELECT gc.* FROM group_contact gc

      INNER JOIN ( SELECT id, group_id, contact_id

                          FROM group_contact

                          GROUP BY group_id, contact_id HAVING count(*) > 1 ) dup_gc

                  ON ( gc.group_id = dup_gc.group_id

                          AND gc.contact_id = dup_gc.contact_id

                          AND gc.id <> dup_gc.id )

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.