Find rows with multiple duplicate fields with Active Record, Rails & Postgres

前端 未结 5 1030
有刺的猬
有刺的猬 2020-12-04 06:07

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

5条回答
  •  暖寄归人
    2020-12-04 06:48

    That error occurs because POSTGRES requires you to put grouping columns in the SELECT clause.

    try:

    User.select(:first,:email).group(:first,:email).having("count(*) > 1").all
    

    (note: not tested, you may need to tweak it)

    EDITED to remove id column

提交回复
热议问题