MySQL: Order by field size/length
Solution 1:
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;
Solution 2:
For those using MS SQL
SELECT * FROM TEST ORDER BY LEN(field)