Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL count number of words in field

I'd like to make an SQL query where the condition is that column1 contains three or more words. Is there something to do that?

like image 805
Bob Avatar asked Jan 07 '15 19:01

Bob


1 Answers

maybe try counting spaces ?

SELECT * 
FROM table
WHERE (LENGTH(column1) - LENGTH(replace(column1, ' ', ''))) > 1

and assume words is number of spaces + 1

like image 99
David Chan Avatar answered Oct 13 '22 20:10

David Chan