MySQL – Count Number Of Words

Blog ideasMySQL doesn’t contain built in function for counting number of words in a column. It’s a very common request so we need use a trick for this purpose.

The query bellow returns number of words separated with a space:

SELECT SUM(LENGTH(column_name) - LENGTH(REPLACE(column_name, ' ', ''))+1)
FROM table_name

Of course, if you replace space with any other character it will be used as a delimiter.

Share This Post

Related Articles

Leave a Reply

 
© 2014 LoneShooter.com. All rights reserved. Site Admin · Entries RSS · Comments RSS
· Designed by Lone Shooter