开发者

sql select a record containing a phrase

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜