Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Query to find words over a certain length without spaces

Posted on 2011-09-27
3
Medium Priority
?
258 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
ID: 36712768
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 1000 total points
ID: 36712788
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
ID: 36713642
Nice one! Thanks a lot
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we’ll look at how to deploy ProxySQL.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month20 days, 19 hours left to enroll

810 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