# Sql query with pagination

**URL:** <https://www.ruby-forum.com/t/sql-query-with-pagination/194611>\
**Category:** Rails\
**Created:** [September 8, 2010, 12:42am UTC](https://www.ruby-forum.com/t/sql-query-with-pagination/194611 "2010-09-08T00:42:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mark](https://www.ruby-forum.com/u/mark)\
**Post date:** [September 8, 2010, 12:42am UTC](https://www.ruby-forum.com/t/sql-query-with-pagination/194611/1 "2010-09-08T00:42:45Z")

</div>

I am Using will\_paginate plugin in a call like :

@homes = Home.paginate(:all, :conditions =\> conditions…

I want to have minimum and maximum price within all @homes searched. How  
would I do that efficiently?  
Since I do pagination, the @homes variable doesn’t contain all the  
“homes” objects, but only partial ones for pagination. Do I have to do  
another query with same conditions without pagination to get it?

---

<div class="post-metadata">

**Author:** ![mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mark](https://www.ruby-forum.com/u/mark)\
**Post date:** [September 8, 2010, 3:04am UTC](https://www.ruby-forum.com/t/sql-query-with-pagination/194611/2 "2010-09-08T03:04:13Z")

</div>

use named scopes, read a bit about them, lets you chain them like this  
Home.ranged(6…9).paginate( etc etc)
