Skip to content

Instantly share code, notes, and snippets.

@SunDi3yansyah
Last active October 1, 2021 14:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SunDi3yansyah/4a28d1b2df8327503623f68e28fa41ea to your computer and use it in GitHub Desktop.
Save SunDi3yansyah/4a28d1b2df8327503623f68e28fa41ea to your computer and use it in GitHub Desktop.
Rails find duplicate records
columns_that_make_record_distinct = [:some_attribute]
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