Ayman Hussein
Ayman Hussein

Reputation: 3857

mysql 'order by' issue with arabic letters

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.

Upvotes: 8

Views: 2222

Answers (3)

M.M.J
M.M.J

Reputation: 76

I had the same problem and I solve it by changing the type to utf16_bin or any _bin.

CREATE TABLE IF NOT EXISTS `test` (
  `id` int(11) NOT NULL,
  `name` varchar(100) COLLATE utf16_bin NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_bin;

Upvotes: 0

juergen d
juergen d

Reputation: 204746

Try to use a persian collation for your table definition. Example

create table emp 
(
   id int,
   name text,
   ...
)
collate utf32_persian_ci;

Upvotes: 1

Hari Ramamurthy
Hari Ramamurthy

Reputation: 96

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;

Upvotes: 1

Related Questions