?
Solved

Query to find words over a certain length without spaces

Posted on 2011-09-27
3
Medium Priority
?
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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 Month10 days, 19 hours left to enroll

770 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