What is the best way to find records with duplicate values across multiple columns using Postgres, and Activerecord?
I found this solution here:
User.f
Get all duplicates with a single query if you use PostgreSQL:
def duplicated_users duplicated_ids = User .group(:first, :email) .having("COUNT(*) > 1") .select('unnest((array_agg("id"))[2:])') User.where(id: duplicated_ids) end irb> duplicated_users