srboisvert srboisvert - 1 year ago 72
Ruby Question

How to find records that have duplicate data using Active Record

What is the best way to find records with duplicate values in a column using ruby and the new Activerecord?

Answer Source

Translating @TuteC into ActiveRecord:

sql = 'SELECT id, COUNT(id) as quantity FROM types GROUP BY name HAVING quantity > 1'
#=>"id, count(id) as quantity").group(:name).having("quantity > 1")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download