SQL Query: order by length of characters?

Is it possible to order sql data rows by the total number of characters?

e.g. SELECT * FROM database ORDER BY data.length()


Solution 1:

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

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).

Solution 2:

SELECT * FROM database ORDER BY Len(data)

Solution 3:

SELECT * FROM table ORDER BY length(data) desc

Where data is varchar field