Node17
Node17

Reputation: 537

How to find records that are associated to the same group more than once?

I need to find if a record id is on the same group id more than once.

group id | record id | comments
--------------------------------
    3          1 
    3          1        
    4          2          

In this case, the record with id 1 is being associated with group id 3 twice.

Is there a query that can provide all records with this behaviour?

Thanks

Upvotes: 0

Views: 49

Answers (1)

gzaxx
gzaxx

Reputation: 17600

This query should do the job:

select t.group_id, t.record_id
from [your_table] t
group by t.group_id, t.record_id
having count(*) > 1

Upvotes: 2

Related Questions