Skip to content

Instantly share code, notes, and snippets.

@rob-murray
Last active November 8, 2024 09:21
Show Gist options
  • Save rob-murray/b3528ffcd71040a9fdf1 to your computer and use it in GitHub Desktop.
Save rob-murray/b3528ffcd71040a9fdf1 to your computer and use it in GitHub Desktop.

Revisions

  1. rob-murray revised this gist Nov 8, 2024. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions find_dups.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    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)
    duplicate_records = Model.where.not(id: Model.select("MIN(id) as id").group(columns_that_make_record_distinct))
  2. 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)