title: SQL Query - Delete duplicates if more than 3 dups?
body: <p>Does anyone have an elegant sql statement to delete duplicate records from a table, but only if there are more than x number of duplicates?  So it allows up to 2 or 3 duplicates, but that's it?</p>
  
  <p>Currently I have a select statement that does the following:</p>
  
  <pre><code>delete table
  from table t
  left outer join (
   select max(id) as rowid, dupcol1, dupcol2
   from table
   group by dupcol1, dupcol2
  ) as keeprows on t.id=keeprows.rowid
  where keeprows.rowid is null
  </code></pre>
  
  <p>This works great.  But now what I'd like to do is only delete those rows if they have more than say 2 duplicates.</p>
  
  <p>Thanks</p>