包含子字符串的SELECT MySQL字段 [英] SELECT MySQL field that contains a substring
本文介绍了包含子字符串的SELECT MySQL字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在MySQL中,使用LIKE很常见.我们这样使用它:WHERE field LIKE '%substring%'
.我们有一个子字符串,而字段有完整的字符串.但是我需要的是相反的东西.我在字段中有子字符串.因此,我希望该行包含我的字符串的子字符串.假设表是:
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
----+-------------------
,我有一个来自用户的字符串:Tell me about admission info
.我需要一个返回admission
的MySQL查询,因为这是用户字符串的子字符串.像这样:
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')
提前谢谢.
推荐答案
查看全文