title: Unique column pairs as A,B or B,A
body: <p>If I have a joining table with two columns, TeamA and TeamB, how can I ensure that each pair is unique?</p>
  
  <p>Obviously I can put a unique composite index on these columns but that will only ensure uniqueness in the order A,B but not B,A correct?</p>
  
  <pre><code>TeamA | TeamB
  -------------
   red  | blue
   pink | blue
   blue | red
  </code></pre>
  
  <p>As you can see, Red vs. Blue has already been specified as the first record and then it is specified again as the last. This should be illegal since they will already be facing each other.</p>
  
  <p><strong>Edit:</strong> Also, is there a way to handle the SELECT case as well? Or the UPDATE? DELETE? Etc..</p>
  
  <p>Also, the idea of Home or Away team has been brought up which may be important here. This initial concept came to me while thinking about how to build a bracketing system on the DB side.</p>