# Find by array of ids in the same order?

**URL:** <https://www.ruby-forum.com/t/find-by-array-of-ids-in-the-same-order/129099>\
**Category:** Rails\
**Created:** [February 14, 2008, 8:27am UTC](https://www.ruby-forum.com/t/find-by-array-of-ids-in-the-same-order/129099 "2008-02-14T08:27:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgudibanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@sgudibanda](https://www.ruby-forum.com/u/sgudibanda)\
**Post date:** [February 14, 2008, 8:27am UTC](https://www.ruby-forum.com/t/find-by-array-of-ids-in-the-same-order/129099/1 "2008-02-14T08:27:44Z")

</div>

Hi,

I am trying to perform:

@people = Person.find(10,14,5,1)

The RUBY is acting intelligent in fetching the rows, it is sorting my  
array and fetching the corresponding rows: Essentially I am returned  
with rows 1,5,10 and 14 in that order…

It is essential for me to retain the order, can I force this happen?

Regards,  
Sandeep G

---

<div class="post-metadata">

**Author:** ![sgudibanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@sgudibanda](https://www.ruby-forum.com/u/sgudibanda)\
**Post date:** [February 14, 2008, 8:29am UTC](https://www.ruby-forum.com/t/find-by-array-of-ids-in-the-same-order/129099/2 "2008-02-14T08:29:29Z")

</div>

Realized it is MYSQL that is acting intelligent in sorting the array,  
can i force this not to happen?

---

<div class="post-metadata">

**Author:** ![sgudibanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@sgudibanda](https://www.ruby-forum.com/u/sgudibanda)\
**Post date:** [February 14, 2008, 2:21pm UTC](https://www.ruby-forum.com/t/find-by-array-of-ids-in-the-same-order/129099/3 "2008-02-14T14:21:06Z")

</div>

Sandeep G. wrote:

> Realized it is MYSQL that is acting intelligent in sorting the array,  
> can i force this not to happen?

ids = [10,14,5,1]  
@people = Person.find ids, :order =\> “field(id,#{ids.join(‘,’)})”

[http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function\_field](http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_field)

–  
We develop, watch us RoR, in numbers too big to ignore.
