# ActiveRecord.find :group option

**URL:** <https://www.ruby-forum.com/t/activerecord-find-group-option/110170>\
**Category:** Rails\
**Created:** [July 23, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/activerecord-find-group-option/110170 "2007-07-23T22:20:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [July 23, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/activerecord-find-group-option/110170/1 "2007-07-23T22:20:44Z")

</div>

I have a very simple find call…

@assets = Asset.find(:all, :group =\> ‘asset\_type\_id’, :order =\> “name”)

I have 3 Asset objects in my database, all of which have asset\_type\_id  
equal to 1. Why does this query only return 1 object?

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [July 23, 2007, 10:29pm UTC](https://www.ruby-forum.com/t/activerecord-find-group-option/110170/2 "2007-07-23T22:29:17Z")

</div>

> I have a very simple find call…  
> @assets = Asset.find(:all, :group =\> ‘asset\_type\_id’, :order =\> “name”)
> 
> I have 3 Asset objects in my database, all of which have asset\_type\_id  
> equal to 1. Why does this query only return 1 object?

Get a good MySQL book to figure out what’s happening. The :group =\>  
‘asset\_type\_id’ call generates the SQL clause “GROUP BY  
asset\_type\_id”. Use this when you want a SUMMARY of all the fields  
with a particular value of asset\_type\_id. So for each value of  
asset\_type\_id, you get ONE record. Usually you’ll also want a COUNT,  
SUM, AVERAGE, or other summary function returned with this record.

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [July 23, 2007, 10:51pm UTC](https://www.ruby-forum.com/t/activerecord-find-group-option/110170/3 "2007-07-23T22:51:10Z")

</div>

OK, after reading your post I found another passage in the Rails book  
about it. I was under the mistaken impression that it sorted them by  
group.

Thanks.
