Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2010
    Posts
    18

    Question Unanswered: 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

  2. #2
    Join Date
    Mar 2006
    Posts
    56
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •