title: How to SELECT INTO with a check on each row before insertion
body: <p>I want to create a table using <code>SELECT INTO</code> but want to avoid creating rows where two of the columns are equal but in different order to two other columns. For example, say I have a query that generates the following data</p>
  
  <pre><code>+----+----+
  |col1|col2|
  +----+----+
  |A   |XYZ |
  +----+----+
  |2   |4   |
  +----+----+
  |WA  |AB  |
  +----+----+
  |W   |B   |
  +----+----+
  |XYZ |A   |
  +----+----+
  </code></pre>
  
  <p>In this case I would want to add all rows except for the last, because it is a flipped duplicate of the first row. Here is a conceptual version of what I've got at the moment:</p>
  
  <pre><code>SELECT
      a.col1 AS col1,
      b.col1 AS col2,
  INTO newTable
  FROM a
  INNER JOIN b
      ON -- some match criteria
  -- If I were to end the query here, it would generate the table shown above
  
  -- my attempt at avoiding cross duplicates:
  WHERE NOT EXISTS ( 
      SELECT x.col1,x.col2
      FROM -- what name do I use here? AS x
      WHERE (x.col1 = col2 AND x.col2 = col1)
  )
  </code></pre>
  
  <p>Note that the criteria for generating the code <em>before</em> that outer <code>WHERE</code> block is quite large, and I would prefer not to have to repeat it within the <code>NOT EXISTS</code> block. How do I approach this problem?</p>