title: Find duplicate sets of data grouped by foreign key
body: <p><a href="https://i.stack.imgur.com/TGlxB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TGlxB.png" alt="enter image description here" /></a></p>
  <p>How to check if the above table contains duplicate group of rows based on id. For ex here first two rows of id 1 are matching with the next two rows of id 2 but id 2 also have the third row which is not matching with any two rows of id 1 so it's not duplicate and there could be n no of ids.</p>
  <p>I tried it to do with the <code>group by</code> and <code>string_agg</code> but it didn't work.</p>
  <p>Here what I tried:</p>
  <pre><code>declare @t2 Table( m1 int, m2 int,n varchar(50),n2 varchar(50), id int)
  
  insert into @t2 values(3,1,'c','',1),(2,1,'s','o',1),(2,1,'s','o',2),(3,1,'c','',2),(3,1,'f','',2)
   
  if exists( SELECT *
      FROM @t2
      GROUP BY m1,m2,n,n2
      HAVING COUNT(*) &gt; 1)
  begin
  select 'Same.'
  end
  else 
  begin
  select 'not found'
  end
  </code></pre>
  <p>Any help here will be great.
  Thanks</p>