Jump to content

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 )

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.