SQL Query: order by length of characters?

I think you want to use this: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_char-length

(MySQL/MariaDB specific)

SELECT * FROM table ORDER BY CHAR_LENGTH(field)

You can use just simply LENGTH(), but beware, because it counts the byte number (which won’t give you the expected result with multibyte strings).

Leave a Comment