SQL search for containing terms

匆匆过客 提交于 2020-01-02 05:13:10

问题


If it possible to search in a table for records of which its name contains a search term?

Thanks


回答1:


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. If you searching through a lot of text, you might want to consider using Sphinx for exemple.




回答2:


Sure. There is the CONTAINS predicate:

... WHERE CONTAINS(name, 'search-term')

There is also the LIKE operator and some DBMS allow for regular expressions.




回答3:


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%'


来源:https://stackoverflow.com/questions/2691917/sql-search-for-containing-terms

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!