# Paginating a find statement with :select =\> "distinct products.\* "

**URL:** <https://www.ruby-forum.com/t/paginating-a-find-statement-with-select-distinct-products/137243>\
**Category:** Rails\
**Created:** [May 10, 2008, 5:05pm UTC](https://www.ruby-forum.com/t/paginating-a-find-statement-with-select-distinct-products/137243 "2008-05-10T17:05:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9bcb4/32.png) [@Carson](https://www.ruby-forum.com/u/Carson)\
**Post date:** [May 10, 2008, 5:05pm UTC](https://www.ruby-forum.com/t/paginating-a-find-statement-with-select-distinct-products/137243/1 "2008-05-10T17:05:02Z")

</div>

My selection of products from a Products table looks like this:

```
# Get products on department promotion
@products = Product.find(:all,
:select => "distinct products.*",
:order => " product_id ",
:joins => " inner join category_products " +
            " on products.product_id =

```

category\_products.product\_id " +  
" inner join categories " +  
" on category\_products.category\_id =  
categories.category\_id ",  
:conditions =\> [“products.on\_department\_promotion = ? " +  
" AND categories.department\_id = ?”, true, params[:id]])

When I try to substitute a pagination statement for the find  
statement, for example:

```
@products = Product.paginate(:all,
:page => params[:page],
:select => "distinct products.*",
:order => " product_id ",
:joins => " inner join category_products " +
            " on products.product_id =

```

category\_products.product\_id " +  
" inner join categories " +  
" on category\_products.category\_id =  
categories.category\_id ",  
:conditions =\> [“products.on\_department\_promotion = ? " +  
" AND categories.department\_id = ?”, true, params[:id]])

the paginage gem/plugin can’t interpret the select distinct statement  
an typically gives an error like:

```
SQLite3::SQLException: near "*": syntax error: SELECT

```

count(distinct  
products.\*) AS count\_distinct\_products\_all FROM products inner  
join  
etc., etc., etc.

Can anyone tell me how to paginate the results of the original find  
statement?

Carson
