Quick Search

Count number of words in a MySQL column

March 5th, 2010 by admin
Leave a reply »

 

This is a general requirement to count number of words in a column of a MySQL database table. But MySQL does not have any built in function to count number of words as it generally has for number of purposes.

But you can do it with a simple trick e.g. you have a column name and want to count number of words in it. This query will return number of words separated with space in a column

SELECT SUM( LENGTH(name) – LENGTH(REPLACE(name, ‘ ‘, ”))+1) FROM table

If you want to count number of words separated by some other string for example comma (,) or semicolon (;), simply replace space with your required character.

Posted in Database

You can follow any responses to this entry through the RSS 2.0 Feed. You can leave a response , or trackback from your own site.

4 commentsAdd your comment
  1. limewire says:

    wow sweet stuff bro.

  2. Johny Deputy says:

    its time i started understand the whole thing about Im!

  3. hello i really enjoy your blog. this is killer info. I wanted to let you know about some killer traffic video courses i have. just swing by and take advantage of my save the family vacation firesale. right now.

  4. Shad Bironas says:

    LOL is that what you young people would say in this cases? Hello there, i’m a 84 years old grandfather and I’ve just found this website in my browser history. My nephew used my laptop the last time he went here, I believe… he says LOL pretty often but I’ve started to undertand what it means only recently but he’s a good boy after all. Keep doing your best guys, Internet is a real blessing and you have no idea how lucky you are. Best wishes by a old man commenting for the first time

 

Leave a Reply

SEO Company India

search engine marketing company India that offers affordable seo services