title: Clean up SQL data before unique constraint
body: <p>I want to clean up some data in a table before putting in a unique constraint on two columns.</p>
  
  <pre><code>CREATE TABLE test (
   a integer NOT NULL,
   b integer NOT NULL,
   c integer NOT NULL,
   CONSTRAINT a_pk PRIMARY KEY (a)
  );
  
  INSERT INTO test (a,b,c) VALUES
   (1,2,3)
  ,(2,2,3)
  ,(3,4,3)
  ,(4,4,4)
  ,(5,4,5)
  ,(6,4,4)
  ,(7,4,4);
  
  -- SELECT a FROM test WHERE ????
  </code></pre>
  
  <p><strong>Output should be <code>2,6,7</code></strong></p>
  
  <p>I am looking for all rows <em>after the first</em> that have duplicated <code>b,c</code></p>
  
  <p>EX:</p>
  
  <ul>
  <li><p>Rows 1,2 have (2,3) as b,c
  Row 1 is ok because it is the first, 2 is not.</p></li>
  <li><p>Rows 4,6,7 have (4,4) as b,c
  Row 4 is ok because it is the first, 6,7 are not.</p></li>
  </ul>
  
  <p>I will then:</p>
  
  <pre><code>DELETE FROM test WHERE a = those IDs;
  </code></pre>
  
  <p>.. and add the unique constraint.</p>
  
  <p>I was thinking about an intersect on test with itself but not sure where to do go from there.</p>