开发者

sql select a record containing a phrase

开发者 https://www.devze.com 2023-02-07 09:35 出处:网络
I want to query a record containing a phrase. for example: I want the search to return the record: \'开发者_运维技巧The needle in the haystack\' with the search phrase \'needle haystack\'

I want to query a record containing a phrase.

for example: I want the search to return the record: '开发者_运维技巧The needle in the haystack' with the search phrase 'needle haystack'

The query will work if I just have 'needle' or just 'haystack' using like% in the where clause.

Is there a way to search with the phrase 'needle haystack'?


SELECT * FROM table WHERE phrase LIKE '%needle%' AND phrase LIKE '%haystack%'

Replace phrase with LOWER(phrase) if you want the search to be case-insensitive (depends on the DB engine and other things, though).


you can also try this

select * from Suppliers where patindex(REPLACE('%' + 'YOUR SEARCH STRING' + '%',' ','%'),CompanyName) > 1
0

精彩评论

暂无评论...
验证码 换一张
取 消