开发者

Query for an exact match for a string in to a column having text fields(more then one strings)

In my data base table i have a field "description" which is a text field. it contains values like it :

This bracelet is composed of round diamond surrounded by milgrain detailing. Its secure setting prevents it from twisting and ensures it will sit impeccably on her wrist.


This stylish design is the perfect accessory for the day or evening. Akoya cultured pearls are lined up by a string of bezel-set round diamond.

I want to query for the columns which contains exact word "diamond"

when i query as select description from tproduct where description like '%diamond%' it give me the result but it runs as wil开发者_StackOverflow社区d card query

where i want to exact match for "diamond"

I did as select description from tproduct where description ='diamond' But it is not giving any result

Please tell me how to query for this.

Thanks Romi


One simple way is to put spaces around the word in your query:

SELECT ... WHERE description LIKE '% diamond %';

That doesn't work so well if your sentence ends with "diamond.", however.

For something much more complex, you really need to use some sort of full-text indexing, which I have no experience with in MySQL.


SELECT .... WHERE ' ' + REPLACE(description,'.','') + ' ' LIKE '% diamond %'

This will work if your sentence starts and/or ends with 'diamond.'

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜