MySQL - How to select data by string length
You are looking for CHAR_LENGTH()
to get the number of characters in a string.
For multi-byte charsets LENGTH()
will give you the number of bytes the string occupies, while CHAR_LENGTH()
will return the number of characters.
SELECT * FROM table ORDER BY LENGTH(column);
Documentation on the LENGTH()
function, as well as all the other string functions, is available here.
Having a look at MySQL documentation for the string functions, we can also use CHAR_LENGTH()
and CHARACTER_LENGTH()
as well.