Just wanted to ask does anyone know how to find the 5 most frequent values in a model colomn for active record.
eg
Country.find(:name)
How would I find the top 5 most common countries
Use the following
Country.group(:name).order('count_id DESC').limit(5).count(:id)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With