views:

286

answers:

2

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

 __________________________________________
| Field Name     | Data Type               |                 
|________________|_________________________|                 
|    id          |   BIGINT (20)           |                 
|________________|_________________________|                 
|    title       |   varchar(25)           |                 
|________________|_________________________|                 
|    description |   text                  |                 
|________________|_________________________|                 

A query like:

SELECT * FROM TEST ORDER BY description DESC;

But I would like to order by the field size/length of the field description. The field type will be TEXT or BLOB.

+3  A: 
SELECT * FROM TEST ORDER BY LENGTH(description) DESC;

The LENGTH function counts bytes. If you want to count (multi-byte) characters, use the CHAR-LENGTH function instead:

SELECT * FROM TEST ORDER BY CHAR-LENGTH(description) DESC;
JG
simple and effective... thank you
Sadi
I have accept your answer before you set it DESC. I have not define this requirement at first. Thank you again :)
Sadi
A: 
SELECT * FROM TEST ORDER BY CHAR_LENGTH(description);
Mike Sherov