How can I order my query by word count? Is it possible?
I have some rows in table, with text fields. I want to order them by word count of these text fields.
Second problem is, that I need to select only these rows, which have for example minimum 10 words, or maximum 20.
Well, this will not perform very well since string calculations need to be performed for all rows:
You can count number of words in a MySQL column like so:
SELECT SUM( LENGTH(name) - LENGTH(REPLACE(name, ' ', ''))+1) FROM table(provided that words are defined as “whatever-delimited-by-a-whitespace”)Now, add this to your query:
Or, add it to the condition: