# Swedish sort order not working

**URL:** <https://www.ruby-forum.com/t/swedish-sort-order-not-working/190070>\
**Category:** Rails\
**Created:** [June 12, 2010, 4:12pm UTC](https://www.ruby-forum.com/t/swedish-sort-order-not-working/190070 "2010-06-12T16:12:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ab992/32.png) [@jeb](https://www.ruby-forum.com/u/jeb)\
**Post date:** [June 12, 2010, 4:12pm UTC](https://www.ruby-forum.com/t/swedish-sort-order-not-working/190070/1 "2010-06-12T16:12:26Z")

</div>

Hi all,

I have a MySQL DB in my production environment with collation set to  
latin1\_swedish\_ci

When I do a simple find and order by ‘name’ the names are not sorted  
in Swedish order. They are “Anna, Östen, Kalle, Rut” when they should  
be “Anna, Kalle, Rut, Östen”.

I guess a simple sort shall work without having to alter the table to  
utf8?

Any idears?

---

<div class="post-metadata">

**Author:** ![jeb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ab992/32.png) [@jeb](https://www.ruby-forum.com/u/jeb)\
**Post date:** [June 14, 2010, 9:45pm UTC](https://www.ruby-forum.com/t/swedish-sort-order-not-working/190070/2 "2010-06-14T21:45:56Z")

</div>

jeb wrote:

> Hi all,
> 
> I have a MySQL DB in my production environment with collation set to  
> latin1\_swedish\_ci

This is not a Rails question; it is a MySQL question. You’ll get better  
answers in a MySQL forum. But…

My recollection is that not just the DB but also each table and each  
field in MySQL can have its own sort order. Make sure these are all set  
properly.

> When I do a simple find and order by ‘name’ the names are not sorted  
> in Swedish order. They are “Anna, ï¿½sten, Kalle, Rut” when they should  
> be “Anna, Kalle, Rut, ï¿½sten”.
> 
> I guess a simple sort shall work without having to alter the table to  
> utf8?

You really _should_ alter the table to UTF8. That way you’ll be able to  
handle any conceivable character.

> Any idears?

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![jeb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ab992/32.png) [@jeb](https://www.ruby-forum.com/u/jeb)\
**Post date:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/swedish-sort-order-not-working/190070/3 "2010-06-17T16:22:19Z")

</div>

On Sat, Jun 12, 2010 at 7:11 AM, jeb [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a MySQL DB in my production environment with collation set to  
> latin1\_swedish\_ci
> 
> When I do a simple find and order by ‘name’ the names are not sorted  
> in Swedish order. They are “Anna, Östen, Kalle, Rut” when they should  
> be “Anna, Kalle, Rut, Östen”.

If you run the query generated by ActiveRecord manually in a MySQL  
console, do you get the result you expect?

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![jeb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ab992/32.png) [@jeb](https://www.ruby-forum.com/u/jeb)\
**Post date:** [June 17, 2010, 4:27pm UTC](https://www.ruby-forum.com/t/swedish-sort-order-not-working/190070/4 "2010-06-17T16:27:03Z")

</div>

On Sat, Jun 12, 2010 at 8:32 AM, jeb [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > If you run the query generated by ActiveRecord manually in a MySQL  
> > console, do you get the result you expect?

> No, I get the wrong result.

Can you construct a query that _does_ return the result you expect?

What do the following commands show?

mysql\> show variables like ‘%collation%’;

mysql\> show variables like ‘%char%’;

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![jeb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ab992/32.png) [@jeb](https://www.ruby-forum.com/u/jeb)\
**Post date:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/swedish-sort-order-not-working/190070/5 "2010-06-17T16:22:48Z")

</div>

No, I get the wrong result.

On 12 Juni, 16:50, Hassan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
