If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Sort records by Word Count

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-03-10, 05:21
andy982183 andy982183 is offline
Registered User
 
Join Date: Mar 2010
Posts: 18
Question Sort records by Word Count

Hii,

Is it possible in MySql to sort records by word count ?

Example:

Andy And Company Ltd - 4 words
Simon And Company - 3 words
Kite Company - 2 words

Thanks.

Reference query...
This query sorts records by char. count

SELECT * FROM Table
ORDER BY { fn LENGTH(NAME) } DESC
Reply With Quote
  #2 (permalink)  
Old 04-03-10, 05:33
Ikviens Ikviens is offline
Registered User
 
Join Date: Mar 2006
Posts: 55
Word counts of your examples equal to the number of spaces plus one, if data like 'Andy And Company Ltd' are stored in a single field. You can use functions in ORDER BY clause.

Since you already know how to count the occurrence of String x within Field col1, it shouldn't be awfully difficult to proceed figure out the function to write in there.
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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On