most frequent value in active record coloumn

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

Answer

Use the following

Country.group(:name).order('count_id DESC').limit(5).count(:id)
Source: stackoverflow
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .