Skip to content

Instantly share code, notes, and snippets.

@FrankFang
Forked from rob-murray/find_dups.rb
Created November 9, 2017 15:35
Show Gist options
  • Save FrankFang/192cd0556efc418e3966ac79873ae08f to your computer and use it in GitHub Desktop.
Save FrankFang/192cd0556efc418e3966ac79873ae08f to your computer and use it in GitHub Desktop.
Rails find duplicate records
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment