columns_that_make_record_distinct = [:some_id, :another_name] duplicate_records = Model.where.not(id: Model.select("MIN(id) as id").group(columns_that_make_record_distinct))