[英]SQL search for containing terms
If it possible to search in a table for records of which its name contains a search term? 如果可以在表中搜索其名称包含搜索词的记录?
Thanks 谢谢
SELECT * FROM `my_table` WHERE name LIKE '%my_search_term%'
or 要么
SELECT * FROM `my_table` WHERE CONTAINS(name, 'search')
But be aware that the LIKE statement is very expensive. 但要注意LIKE语句非常昂贵。 If you searching through a lot of text, you might want to consider using Sphinx for exemple.
如果您搜索大量文本,可能需要考虑使用Sphinx作为示例。
Sure. 当然。 There is the
CONTAINS
predicate: 有
CONTAINS
谓词:
... WHERE CONTAINS(name, 'search-term')
There is also the LIKE
operator and some DBMS allow for regular expressions. 还有
LIKE
运算符和一些DBMS允许正则表达式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.