简体   繁体   English

SQL搜索包含的术语

[英]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允许正则表达式。

It sounds like what you are looking for is LIKE 这听起来像你正在寻找的是喜欢

-- Get all people with phone numbers starting with 920
SELECT * FROM People WHERE PhoneNumber LIKE '920%'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM