title: Delete duplicate records based on multiple columns
body: <p>In our system we run hourly imports from an external database. Due to an error in the import scripts, there are now some duplicate records.</p>
  
  <p>A duplicate is deemed where any record has the same <code>:legacy_id</code> and <code>:company</code>.</p>
  
  <p>What code can I run to find and delete these duplicates?</p>
  
  <p>I was playing around with this:       </p>
  
  <pre><code>Product.select(:legacy_id,:company).group(:legacy_id,:company).having("count(*) &gt; 1")
  </code></pre>
  
  <p>It seemed to return some of the duplicates, but I wasn't sure how to delete from there?</p>
  
  <p>Any ideas?</p>