Reputation: 1291
I have a column which contains many records with one word in common (e.g Channel names):
| channel |
--------------------------
| Fox |
| Fox Life |
| Fox News |
| Fox Action |
| Fox Movies |
And the search criteria is: "Channel Fox News"
Now I'd like to select the only row that have Fox News.
I've tried so many things, like split the string by spaces, or using LIKE with no success, because the word "Fox" always select all five records.
note that its has to be word level match.
thanks
Upvotes: 0
Views: 447
Reputation: 1
Just both words with a like should do the trick:
select name from channel where name like '%fox%' and name like '%news%';
Upvotes: 0
Reputation: 26784
This screams for fulltext index
ALTER TABLE T add FULLTEXT index(channel);
You search with
SELECT * FROM t WHERE MATCH (channel)
AGAINST ('+Fox +News' IN BOOLEAN MODE);
plus sign means that word HAS to exist in the column There are a couple of things you need to pay attention to:
the minimum size of the word searched
and stop words
Upvotes: 2
Reputation: 1269773
How about using like
?
where lower(channel) like '%fox news%'
Upvotes: 0