2

I am trying to come up with a query that will select a row if a column has at least X words in it. For example:

SELECT * FROM TABLE IF COLUMN <has >= 3 words>

Coming up empty though. Any ideas?

1
  • How do you define word? Commented Sep 2, 2014 at 14:33

1 Answer 1

5

3 words need at least 2 spaces. You can count the spaces in your column

select * from your_table
where length(your_column) - length(replace(your_column, ' ', '')) > 1
Sign up to request clarification or add additional context in comments.

3 Comments

+1 Exactly! Oh my god, that was fast. Hardly could read the question when you've already answered it
@AnkitBajpai: No, >1 means at least 2, which are 2 spaces for 3 words
Yupp, You are very right. I apologise for my wrong interpretation of your great logic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.