Ruby-on-Rails: Selecting distinct values from the model

Rails 2

If you are still on rails 2 you will need to use:

Client.select('distinct(name)')

Rails 3

If you are on Rails 3 you will need to use:

Client.select(:name).uniq

If you look at the equivalent section of the rails 3 guide you can see the difference between the two versions.

Rails 4+

The .distinct option was added for rails 4 which is what the latest guides refer to.

Client.select(:name).distinct

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)