Solved

Query to find words over a certain length without spaces

Posted on 2011-09-27
3
232 Views
Last Modified: 2012-05-12
Hi all,

Hopefully a quick one - I hav a table full of words and phrases and trying to return anything over length 15 without being multiple words (i/e/ no spaces).

So far I have:

SELECT *
FROM `words`
WHERE length( trim( word ) ) >15
LIMIT 0 , 30

Open in new window


But need to exclude phrases with spaces - had a look at REGEXP '[:space:]' but can't seem to get that to work in the query.

So a sudo query:

select * from words where word is longer than 20 but make sure it is a word and not a phrase with spaces

Cheers
0
Comment
Question by:dolythgoe
  • 2
3 Comments
 
LVL 23

Expert Comment

by:nemws1
Comment Utility
So if it's a phrase that contains a 15 character word, but there's a space in the field, you don't want it, right?

If so, how about this:
SELECT *
FROM `words`
WHERE word REGEXP '[a-z]{15}'
  AND WORD NOT LIKE '% %'
;

Open in new window

0
 
LVL 23

Accepted Solution

by:
nemws1 earned 250 total points
Comment Utility
It looks like some of your words might have trailing/starting spaces that don't concern you.  If so, you're on the right track with TRIM() - just add it before the NOT LIKE:
SELECT *
FROM `words`
WHERE word REGEXP '[a-z]{15}'
  AND TRIM(word) NOT LIKE '% %'
;

Open in new window

0
 

Author Closing Comment

by:dolythgoe
Comment Utility
Nice one! Thanks a lot
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now