Counting Distinct Records In Rails
July 13th, 2006
If you ever need to count your Rails records based on a distinct column, here is a simple solution:
Gift.count_by_sql("select count(distinct url) from gifts")
In this example, I am counting the number of distinct gift urls from my gifts table.
Subscribe to the feed!
Leave a Reply