order query results by field length?

This is a discussion on order query results by field length? within the MySQL Database forums, part of the Database Forums category; Anyone know of an easy way to order results of a query by the length of one of the fields? ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-19-2006
cronoklee@hotmail.com
 
Posts: n/a
Default order query results by field length?

Anyone know of an easy way to order results of a query by the length of
one of the fields?
ie. the record with the longest text in the 'description' field is
returned first?

Cheers,
Ciarán

Reply With Quote
  #2 (permalink)  
Old 09-19-2006
Bill Karwin
 
Posts: n/a
Default Re: order query results by field length?

cronoklee@hotmail.com wrote:
> Anyone know of an easy way to order results of a query by the length of
> one of the fields?
> ie. the record with the longest text in the 'description' field is
> returned first?


Yes, you can put expressions into the ORDER BY clause:

SELECT ...
FROM ...
ORDER BY LENGTH(description) DESC

Regards,
Bill K.
Reply With Quote
  #3 (permalink)  
Old 09-19-2006
cronoklee@hotmail.com
 
Posts: n/a
Default Re: order query results by field length?

Brilliant! worked a charm Thanks Bill!

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:13 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0