Skip to content

Instantly share code, notes, and snippets.

@jeanfbrito
Forked from rob-murray/find_dups.rb
Created September 29, 2021 00:20
Show Gist options
  • Select an option

  • Save jeanfbrito/53746a2d6a6a6ccc8ebfbb0bcc4751f3 to your computer and use it in GitHub Desktop.

Select an option

Save jeanfbrito/53746a2d6a6a6ccc8ebfbb0bcc4751f3 to your computer and use it in GitHub Desktop.

Revisions

  1. Robert Murray created this gist Oct 27, 2015.
    4 changes: 4 additions & 0 deletions find_dups.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    columns_that_make_record_distinct = [:some_id, :another_name]
    distinct_ids = Model.select("MIN(id) as id").group(columns_that_make_record_distinct).map(&:id)

    duplicate_records = Model.where.not(id: distinct_ids)