Reputation: 65
I have been trying to solve this problem for hours, but I dont know how to approach it, so I would need a push to a right direction.
I want to create a page where users can find the appropriate word, by providing word length and characters.
For example, user wants to find all the 5 letter words, where the second letter is R and fourth V, like this:
_R_V_
I have a table with column WORDS with words "letter", "moon", "drive", "mrive" and the query should return: "drive" and "mrive".
Is it possible to do it in MySQL?
While I was looking for the direction I found that I should create a trie structure. I dont know how to do that, but I will learn it if there is no easier way.
Upvotes: 3
Views: 60
Reputation: 40491
Yes, you can use LIKE
:
SELECT * FROM YourTable t
WHERE t.word_col LIKE '_R_V_'
_
Wildcard stands for any single character. This will also force the string to be 5 characters in length, since %
wildcard is not used.
You can find a great explanation about LIKE
wildcards in the link above.
Upvotes: 4