Reputation:
In MySQL, how can I order my query by character count?
Upvotes: 9
Views: 10987
Reputation: 488434
Try using the LENGTH
function:
SELECT * FROM table ORDER BY LENGTH(myField);
Depending on what you're doing, you might want to use CHAR_LENGTH
instead:
A multi-byte character counts as a single character. This means that for a string containing five two-byte characters, LENGTH() returns 10, whereas CHAR_LENGTH() returns 5.
If you don't know what that means, you probably want LENGTH
.
Upvotes: 23