title: How do I determine if a group of data exists in a table, given the data that should appear in the group's rows?
body: <p>I am writing data to a table and allocating a "group-id" for each batch of data that is written.  To illustrate, consider the following table.</p>
  
  <pre><code>GroupId  Value
  -------  -----
        1      a
        1      b
        1      c
        2      a
        2      b
        3      a
        3      b
        3      c
        3      d
  </code></pre>
  
  <p>In this example, there are three groups of data, each with similar but varying values.</p>
  
  <p>How do I query this table to find a group that contains a given set of values?  For instance, if I query for (a,b,c) the result should be group 1.  Similarly, a query for (b,a) should result in group 2, and a query for (a, b, c, e) should result in the empty set.</p>
  
  <p>I can write a stored procedure that performs the following steps:</p>
  
  <ul>
  <li>select distinct GroupId from Groups -- and store locally</li>
  <li>for each distinct GroupId: perform a set-difference (<code>except</code>) between the input and table values (for the group), and vice versa </li>
  <li>return the GroupId if both set-difference operations produced empty sets</li>
  </ul>
  
  <p>This seems a bit excessive, and I hoping to leverage some other commands in SQL to simplify.  Is there a simpler way to perform a set-comparison in this context, or to select the group ID that contains the exact input values for the query?</p>