# Find and order

**URL:** <https://www.ruby-forum.com/t/find-and-order/165061>\
**Category:** Rails\
**Created:** [April 8, 2009, 6:51pm UTC](https://www.ruby-forum.com/t/find-and-order/165061 "2009-04-08T18:51:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [April 8, 2009, 6:51pm UTC](https://www.ruby-forum.com/t/find-and-order/165061/1 "2009-04-08T18:51:45Z")

</div>

I have a find that look likes this:

@values = UdidValue.find(:all,  
:conditions =\> [‘udid\_id = ?’, x.id], :order =\> ‘value ASC’)

The problem is that ‘value’ could be a street address, for example,  
numbers. So, when I do the :order if they are strings the get order  
wonderfully, but in one case I have values that are numbers, for  
example, 234, 233, 219, 25, 199, which get order as 199, 25, 219, 233,  
234. Which is not what I want. I would like to order as 25, 199, 219,  
233, 234.

Is there a way to get the order to order properly regardless if it is a  
number of string? Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [April 8, 2009, 7:19pm UTC](https://www.ruby-forum.com/t/find-and-order/165061/2 "2009-04-08T19:19:19Z")

</div>

> 233, 234.
> 
> Is there a way to get the order to order properly regardless if it  
> is a  
> number of string? Thanks,

Google for “natural sort” for your particular database.

If mysql, maybe…  
[http://blog.feedmarker.com/2006/02/01/how-to-do-natural-alpha-numeric-sort-in-mysql/](http://blog.feedmarker.com/2006/02/01/how-to-do-natural-alpha-numeric-sort-in-mysql/)
