UTF8 sorting order with MySQL

20 March 2007 13:00 (EST)
By default MySQL sorts UTF8 fields using following order:
  1. Numbers,
  2. English characters, and than
  3. Non-English characters.
But if you need to display fields with non-English characters before anything else, you can use following SQL statement:

SELECT name, IF(name REGEXP '^[a-zA-Z0-9]', 0, 1) AS sort FROM test ORDER BY sort DESC, name

Discussion (1 comment)

Peter Peter: 6 February 2008 02:57 (EST)

Nice! Thanks

Add your comment
*
*
*
*
*

Captcha Code Please enter the number on the left.
Sorry for asking you to do so.
Reload image