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)