# Order of results from find(array)

**URL:** <https://discuss.rubyonrails.org/t/order-of-results-from-find-array/15326>\
**Category:** rubyonrails-talk\
**Created:** [July 5, 2007, 7:27pm UTC](https://discuss.rubyonrails.org/t/order-of-results-from-find-array/15326 "2007-07-05T19:27:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_T](https://avatars.discourse-cdn.com/v4/letter/c/a8b319/32.png) [@Chris\_T](https://discuss.rubyonrails.org/u/Chris_T)\
**Post date:** [July 5, 2007, 7:27pm UTC](https://discuss.rubyonrails.org/t/order-of-results-from-find-array/15326/1 "2007-07-05T19:27:15Z")

</div>

Dave wrote:

> Hi all,
> 
> I'm using find to query my database using an array of IDs that represent the records I want to pull. But when the results come back they are in a different order than that I requested them in.
> 
> For instance, I have this array of IDs:
> 
> ids = [6, 4, 1, 5, 2, 3]
> 
> I want to pull the records with these IDs from the database so I use:
> 
> @records = Model.find(ids)
> 
> The result from this query comes back in numerical order (which is what I don't want), so the records would be ordered:
> 
> [1, 2, 3, 4, 5, 6]
> 
> \*not\* what I want, I really want the same order: [6, 4, 1, 5, 2, 3]
> 
> is there any way to maintain the order of the records? So the order of the IDs in the array I requested the records with?
> 
> Thanks in advance!

If you're using MySQL you might want to investigate FIELD. This is from memory by I managed this with something like :order =\>"FIELD(my\_table.id, '6, 4, 1, 5, 2, 3'"

No idea about other DBs

Hope this helps Chris
