# Will\_paginate with include option

**URL:** <https://www.ruby-forum.com/t/will-paginate-with-include-option/157399>\
**Category:** Rails\
**Created:** [January 10, 2009, 6:10pm UTC](https://www.ruby-forum.com/t/will-paginate-with-include-option/157399 "2009-01-10T18:10:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankit2584](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@ankit2584](https://www.ruby-forum.com/u/ankit2584)\
**Post date:** [January 10, 2009, 6:10pm UTC](https://www.ruby-forum.com/t/will-paginate-with-include-option/157399/1 "2009-01-10T18:10:58Z")

</div>

Hello,  
I am using will\_paginate and want to use eager loading. but when i use  
the include and order option i get an error. I am using mssqlserver2000  
as database

@people =  
Person.paginate(:include=\>[:relations],:conditions=\>[‘People.id NOT IN  
(Select person\_id from  
people\_relations)’],:per\_page=\>20,:page=\>params[:page],:order=\>‘last\_name  
ASC, first\_name ASC’)

DBI::DatabaseError: Execute  
OLE error code:80040E14 in Microsoft OLE DB Provider for SQL Server  
ORDER BY items must appear in the select list if SELECT DISTINCT  
is specified.  
HRESULT error code:0x80020009  
Exception occurred.: SELECT DISTINCT TOP 20 people.id FROM people LEFT  
OUTER JOIN people\_relations ON people\_relations.person\_id = people.id  
LEFT OUTER JOIN relations ON relations.id = people\_relations.relation\_id  
WHERE (People.id NOT IN (Select person\_id from people\_relations)) ORDER  
BY last\_name ASC, first\_name ASC

but when i remove the include option it works fine but the results are  
not sorted. Please help by last\_name.  
Thank you.
