Forum Moderators: coopster

Message Too Old, No Replies

Need help with a sql select query

Simple question for guru

         

one_mind

3:20 am on Jun 25, 2006 (gmt 0)

10+ Year Member



Hi,

I was hoping someone could tell me if it was possible to select all words containing ceratin letters.

Eg

If i had a table wit a word column that had a huge list of words and i wanted to select every word that contained all these letters "qdsa".

Then it would return the words:

quads
quidas

ect

but wouldn't return

queen

because queen does not contain all letters specified.

Would it be something like this:

select * from word where word = "qsda";

THat doesn't work by the way :)

Any help would be great.

Thanks

mcavic

4:18 am on Jun 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The only thing I can think of is

select * from words
where word like '%q%'
and word like '%d%'
and word like '%s%'
and word like '%a%'

If you did:
select * from words where word like '%q%d%s%a%'
then the letters q, d, s, and a would have to appear in that same order.

henry0

11:56 am on Jun 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could read the whole thing as an array, explode [us3.php.net] it add a symbol like ¦ as a marker, then read each word, do a Preg_match [us3.php.net] to find those words matching your regex pattern.

As per the manual, explode example
<<<<<
function explode_with_keys($seperator, $string)
{
$output=array();
$array=explode($seperator, $string);
foreach ($array as $value) {
$row=explode("=",$value);
$output[$row[0]]=$row[1];
}
return $output;
}
>>>>