'Select word in dB that is part of a given word

I've created a database that contains a bunch of words such as itch, mitch, hell. Is there any query I can make so that if given a variable, for example Mitchell, it will return me the words it can find inside of it that also exist in the dB such as itch, mitch, hell?

sql


Solution 1:[1]

You can achieve what you are after with locate()

In MySQL the following would work

SELECT 
    id,
    word, 
    LOCATE(word, LOWER('Mitchell')) 
FROM 
    words
WHERE  LOCATE(word, LOWER('Mitchell')) > 0

You can play with it here: http://sqlfiddle.com/#!9/2fdd22b/2/0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1