Using LIKE is very common in MySQL. We use it like this: WHERE field LIKE '%substring%'. Where we have a substring and field has full string. But what I need is something opposite. I have substrings in field. So, I want that row which contains a substring of my string. Suppose the table is:
----+-------------------
id | keyword
----+-------------------
1 | admission
----+-------------------
2 | head of the dept
----+-------------------
and I have a string from user: Tell me about admission info. I need such a MySQL query that returns admission as this is a substring of user string. Something like:
SELECT keyword FROM table WHERE (keyword is a substring of 'Tell me about admission info')
thanks in advance.
解决方案
You re looking for the LIKE operator
Pattern matching using SQL simple regular expression comparison.
Returns 1 (TRUE) or 0 (FALSE). If either expr or pat is NULL, the
result is NULL.
Something like
SELECT keyword
FROM table
WHERE ('Tell me about admission info' LIKE CONCAT('%', keyword, '%'))