Jump to content

selecting words based on occurrance of letters, etc...


.josh

Recommended Posts

Okay I'm fiddling around with this list of words and I'm just trying to figure out what kind of neat things I can do with mysql, as far as selecting words.  So I thought I'd try selecting all words in my list, based on for example, how many s's are in it.  For example, I want to select all words that contain exactly 4 s's in it

Now, after some researching, I came up with the following:

[code]
SELECT * FROM word_list WHERE length(word) - length(replace(word, 's', '')) = 4
[/code]

This works great! However, I am running into some problems when trying to do the same thing, only selecting words with (for instance) [i]more than[/i] 4 s's in it, or [i]less than[/i] 4 s's in it.  It returns the results just fine, but I can't seem to wrap my head around how to order it by occurance. 

I am thinking I have to somehow do something like

[code]
SELECT count(length(word) - length(replace(word,'s','')) as d, * FROM word_list WHERE length(word) - length(replace(word, 's', '')) = 4 order by d
[/code]

but obviously that doesn't work... Am I even remotely on the right track here?  I know how to manipulate a list of words just fine with php. I can pull them all out and into an array and then sort it out just fine using some regex and stuff...but dealing with 58,000 words.. i'm thinking I should make mysql do the work, if I can somehow get it to work, lol..
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.