Current Article:

How to find values that contain less than N words in SQL?

How to find values that contain less than N words in SQL?

Try this SQL query:

select *
from table_name
where length(keyword) - length(replace(keyword, ' ', '')) + 1 < N

where N is your number of words.

So this takes the length of the whole string minus the length of the string without spaces (calculating the # of spaces), and then adds one (ie. if a string has one space that means there are 2 words not 1 word), and filters out any rows where the calculation is not < N.