0

I have a query string like This is a computer. And I have some words in database like computer, This, machine.

I want to find the words which are the substrings of the query string. For the example above, I will get This and computer.

How to write the mysql statement?

0

3 Answers 3

3

You can do something like below using INSTR() function

SELECT * FROM your_table
WHERE INSTR('This is a computer', word) > 0
Sign up to request clarification or add additional context in comments.

Comments

1
SELECT
words
FROM
table_with_words
WHERE 'This is a computer' LIKE CONCAT('%', words, '%');

Comments

0

If you have many words in table, mb, preferable will be using of such query:

SELECT word
FROM table_with_words
WHERE FIND_IN_SET(word, REPLACE('This is a computer', ' ', ',')) != 0

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.