Reputation: 6109
I have a MySQL database with thousands of rows in it. Let's assume each row only has one column and each cell contains a Unicode word (i.e. Chinese word). How do I sort the records so the result set comes back with the word that has the least # of characters first?
For example: If I have AA, BB, CCC, D, EEEE, then I want the result set to be sorted as such: D, AA, BB, CCC, EEEE
Thank you.
Upvotes: 1
Views: 97
Reputation: 39487
You can use char_length(your_column)
as unicode character will take more than one byte.
select * from table
order by char_length(col), col;
Upvotes: 2
Reputation: 40481
First order by the length of the column, and then by the column it self :
SELECT *
FROM YourTable
ORDER BY length(YourCol),
YourCol
Upvotes: 0