title: SQL avoid many to many groups with identical members
body: <p>I have a list of conditions.
  These conditions can be grouped.
  When creating groups, I want to avoid duplicate groups, meaning they have the same members.
  the ID's are unique identifiers, there is a unique constraint on the Name of the condition.</p>
  <p><a href="https://i.stack.imgur.com/soyzj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/soyzj.png" alt="enter image description here" /></a></p>
  <p>For example, I have 3 conditions, being &quot;Painted&quot;, &quot;Oiled&quot;, &quot;Protected&quot;.</p>
  <p>I want to make groups of Painted &amp; Protected and Oiled &amp; Protected. Since there are multiple applications, it is possible that they want to create the groups at the same moment</p>
  <p>In code, I first try to retrieve the group with the matching members. If there is no group found, we create it. With multiple threads or applications this introduces a race condition where there can be created in the database.</p>
  <p>Is there a way to avoid this in SQL or in code</p>