MySQL: Order by field size/length
SELECT * FROM TEST ORDER BY CHAR_LENGTH(description);
SELECT * FROM TEST ORDER BY LENGTH(description) DESC;
The LENGTH
function gives the length of string in bytes. If you want to count (multi-byte) characters, use the CHAR_LENGTH
function instead:
SELECT * FROM TEST ORDER BY CHAR_LENGTH(description) DESC;
For those using MS SQL
SELECT * FROM TEST ORDER BY LEN(field)