[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Alphabetical order in greek

Posted on 2005-05-14
Medium Priority
Last Modified: 2013-12-12

I have a query that fetches all data from a table in alphabetical order using the "...order by col_name asc..." command. The problem is that the data in this column is not in english but in greek and they are not coming in the right order. Any idea?
Question by:MZ_24976

Expert Comment

ID: 14033065
You should set your server, database or table to use a Greek character set, as well as a Greek collation.

The character set determines how the characters are stored in the database (and WHICH characters can be stored) - collations determine how the characters are compared. If you use a Greek collation (found under a Greek character set, or perhaps the Unicode character set), your ORDER BY clauses will work as you want them to do. In any case, check your database server's manual.

If you do not have administrative access to your database server, you could let PHP handle locales:

setlocale(LC_ALL, "ell"); /* "ell" might not be the proper locale name... "greek"? "gre"? "el_gre"? */

Now strcoll() will work just like strcmp(), only using the Greek locale.

...so something like:

uasort(array_of_strings_in_Greek, "strcoll");

will do, perhaps?

Author Comment

ID: 14034185
I tried this in phpmyadmin
ALTER DATABASE mydb COLLATE greek_general_ci

but I took an error:
#1064 - You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'DATABASE mydb COLLATE greek_general_ci' at line 1

I tried also this in my php file, but I took again an error:
SELECT * FROM mydb ORDER BY a COLLATE greek_general_ci;

Accepted Solution

aib_42 earned 200 total points
ID: 14053567
I believe the syntax for MySQL is ALTER DATABASE <name> CHARACTER SET <charset> COLLATE <collate>.

Strangely enough, I couldn't find "ALTER DATABASE" in the MySQL manual, but you could always use ALTER TABLE on individual tables...

Collations are subsets of character sets, so you must specify a character set while specifying a collation.

Assisted Solution

douglasmbeck earned 200 total points
ID: 14738766
I believe that in MySQL, unlike Access and MS SQL, the collation is set to the column not the database or table. The following link may help you set the correct collation to the columns.


Its easiest if you set the collation when you create the database. It is difficult to change the collation after the fact unless you have admin access to the database.

In MyPHPadmin i would suggest using the dropdown for the collation instead of creating your own SQL statement, as the "alter database" may only work if you have admin access and you can "flush logs" to clear out any unwanted entries. In this case the columns would "inherit" the collation from the table.  
LVL 10

Expert Comment

by:Kshitij Ahuja
ID: 15679775
No comment has been added to this question in more than 21 days,so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
[Points Split {aib_42} and {douglasmbeck}]

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Kshitij Ahuja
EE Cleanup Volunteer

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month18 days, 16 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question