MySQL - How to select data by string length
Solution 1:
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.
Solution 2:
SELECT * FROM table
ORDER BY LENGTH(column);
Documentation on the LENGTH()
function, as well as all the other string functions, is available here.
Solution 3:
Having a look at MySQL documentation for the string functions, we can also use CHAR_LENGTH()
and CHARACTER_LENGTH()
as well.