-
-
Save Tzolkin/693d83a8b8eeae67358cfbb951ad77da to your computer and use it in GitHub Desktop.
Rails find duplicate records
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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