0

我正在尝试使用包含部分字符串的列从表中获取数据

表search_data:

id      data

 1      news   
 2      today     
 3      latest

当我使用关键字“新闻”时

 select * from search_data where data like '%news%'

它正在获取结果。但是当我使用关键字“最新消息”时

select * from search_data where data like '%latest news%' 

它不工作它显示一个空的结果集。

有人可以帮我查询。

谢谢。

4

4 回答 4

1

You can add a FULLTEXT index so that you can use MATCH AGAINST :

select 
  * 
from 
  search_data 
where 
  match(data) against ('latest news' IN BOOLEAN MODE) 

This would be the most efficient way, you can read more here

于 2013-06-05T09:51:17.117 回答
0

我不知道你的意思,但我想你想做一些事情,比如这个 select * from search_data where data like '%latest%' OR data like '%news%'

于 2013-06-05T09:56:09.723 回答
0

select * from search_data where data like '%latest news%' 在这个查询中你提到了最新消息,这意味着结果必须在字符串中包含“最新消息”,因为在你的数据集中它不存在如何最新和新闻分别呈现你可以在查询中使用“or”和“and”运算符

于 2013-06-05T10:03:20.483 回答
0

It's because you're looking for the complete string 'latest news' with text either side of it. You will need to do where data like '%news%' or data like '%latest%' to achieve a search for both keywords where they are not contained on the same row

于 2013-06-05T09:50:09.190 回答