That's right, it works like a dog and is limited to working with one limiter, but hopefully gives you an idea.
SELECT aWord, COUNT(*) AS WordOccuranceCount FROM (SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(concat(SomeColumn, ' '), ' ', aCnt), ' ', -1) AS aWord FROM SomeTable CROSS JOIN ( SELECT a.i+bi*10+ci*100 + 1 AS aCnt FROM integers a, integers b, integers c) Sub1 WHERE (LENGTH(SomeColumn) + 1 - LENGTH(REPLACE(SomeColumn, ' ', ''))) >= aCnt) Sub2 WHERE Sub2.aWord != '' GROUP BY aWord ORDER BY WordOccuranceCount DESC LIMIT 10
It depends on the availability of a table called integers, with one column i with 10 rows with values ββfrom 0 to 9. It processes up to ~ 1000 words, but can be easily changed to handle a large number (but it will slow down even more).
source share