SQL Find duplicate sets

Posted by Aheho on Stack Overflow See other posts from Stack Overflow or by Aheho
Published on 2013-11-07T15:34:46Z Indexed on 2013/11/07 15:53 UTC
Read the original article Hit count: 217

Filed under:
|

given this Schema:

 table tblSET 
    SetID int  PK
    SetName nvarchar(100) 


 Table tblSetItem 
    SetID int  PK
    ItemID int PK

tblSetItem.SetID is a FK into the tblSet Table.

Some data:

tblSet

 SetID    SetName
     1    Red
     2    Blue
     3    Maroon
     4    Yellow
     5    Sky

tblSetItem

 SetID    ItemID
     1       100
     1       101
     2       100
     2       108
     2       109
     3       100
     3       101
     4       101
     4       108
     4       109
     4       110
     5       100
     5       108
     5       109

I'd like a way to identify which sets contain the same items. In the example above Red and Maroon contain the same items (100,101) and Blue and Sky contain the same values (100,108,109)

Is there a sql query which would provide this answer?

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server-2008-r2