So 'awesome document' LIKE '%doc%' is true, because doc is a sub-string. But, I want it to be false while 'awesome doc' or 'doc awesome' or 'awesome doc awesome' should be true. How can I do with with a like?
I'm using sqlite, so I hope I don't have to use something that isn't available.
To run a “whole words only” search using a regular expression, simply place the word between two word boundaries, as we did with ‹ \bcat\b ›. The first ‹ \b › requires the ‹ c › to occur at the very start of the string, or after a nonword character.
SQL pattern matching allows you to search for patterns in data if you don't know the exact word or phrase you are seeking. This kind of SQL query uses wildcard characters to match a pattern, rather than specifying it exactly. For example, you can use the wildcard "C%" to match any string beginning with a capital C.
How about split it into four parts -
[MyColumn] Like '% doc %' OR [MyColumn] Like '% doc' OR [MyColumn] Like 'doc %' OR [MyColumn] = 'doc'
Edit: An alternate approach (only for ascii chars) could be:
'#'+[MyColumn]+'#' like '%[^a-z0-9]doc[^a-z0-9]%'
(You may want to take care of any special char as well)
It doesn't look like, but you may want to explore Full Text Search and Contains, in case that's more suitable for your situation.
See: - MSDN: [ ] (Wildcard - Character(s) to Match) (Transact-SQL)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With