Skip to content
Advertisement

MySQL: Order by field size/length

Here is a table structure (e.g. test):

Field Name Data Type
id BIGINT (20)
title varchar(25)
Description Text

A query like:

But I would like to order by the field size/length of the field description.

The field type will be TEXT or BLOB.

Advertisement

Answer

The LENGTH function gives the length of string in bytes. If you want to count (multi-byte) characters, use the CHAR_LENGTH function instead:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement