Reputation: 2117
I am using User.where("name LIKE ?", "frodo")
to find users with similar names.
It may return the following users
How would I group all users by similar names (partially the same)?
Upvotes: 0
Views: 604
Reputation: 3356
From Divyang's answer, one small change to group users by name:--
User.where(["name LIKE ?", "frodo%"]).group(:name)
Upvotes: 1
Reputation: 998
Try this
User.find(:all, :conditions => ["name LIKE ?", "frodo%"])
or
User.where(["name LIKE ?", "frodo%"])
it return array of all user which name start with frodo.
Upvotes: 2
Reputation: 6574
ActiveRecord provides a way to support group by clause. Checkout http://guides.rubyonrails.org/active_record_querying.html#group
Upvotes: 0