tags:

views:

54

answers:

2

hi

consider I've a tables which has all the dictionary words,

I want to fetch the list of words from the db which can be formed with the given set of alphabets..

for this what could be query???..

I thought of fetching every character using substr and comparing whether its present in a list and word length less than or equal to given set of alphabets..

for example

if i give the following set of alphabets,

I , L, S, N, N, E

then i should be able to get the words like the following ones,

SIN, NIL, INN, INS, LINEN, LINENS, LINE, SINE, LENS etc.,,

What would be the query?

A: 

There is no way (that I know of) to search for a word in a db formed by a list of letters in mySQL. The easieest way of doing so would be to generate beforehand a list of possible words and selecting from the database these words (pseudo-code):

foreach(word in possible_word_list)
{
    SELECT * FROM dictionary WHERE dictionary.word=word
}

and to generate the possible word list:

function get_possible_word_list(letters_list)
{
    word_list = array();
    foreach(letter in letters_list)
    {
        word_list.add( letter + get_possible_word_list(letters_list.remove(letter));
    }
    return word_list;
}

Or something like that.

David Menard
+1  A: 
SELECT * 
  FROM dictionary 
 WHERE word REGEXP '^[ILSNE]{1,6}$';

Not a perfect solution, but it might give you something to work with

Mark Baker