Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql 'order by' issue with arabic letters

Tags:

mysql

I have Arabic words in my database:

Example:

أحمد يحيى
احمد اسعد

The question is:

I want to get the names sorted by name.

The expected result is:

احمد اسعد
أحمد يحيى

But I got:

أحمد يحيى 
احمد اسعد

أ before ا

I tried this

select name from emp order by name; 

please help.

like image 609
Ayman Hussein Avatar asked Nov 01 '12 12:11

Ayman Hussein


1 Answers

Can you please check your database collations, they should either be set to utf8_general_ci or utf8_unicode_ci. This should let you perform order by etc correctly.

If running a stand alone query try this:

SET NAMES 'utf8';
SET CHARACTER SET utf8;
select name from emp order by name;
like image 118
Hari Ramamurthy Avatar answered Nov 13 '22 14:11

Hari Ramamurthy