Well the basic scenario is that the user can enter some search terms into a textbox, separated by commas, like so:
"purple, monkey, dishwasher"
What I need my app to do, is search for each of the terms they enter. I can split the text they enter into it's individual parts, so all I need to do now is have the app search for them.
The field it's looking in contains a title for a forum thread. So in the database there might be a thread called "How to search for a monkey in the forest", for example.
When the user enters "purple, monkey, dishwasher" into the search box, I want my app to search the thread title field for the words "purple", "monkey", and "dishwasher", and match any thread title that has at least one of the words in.
Doing it like this:
SELECT fields
FROM table
WHERE ThreadTitle IN ('purple', 'monkey', 'dishwasher');
... doesn't work, because it only matches thread titles where the
complete title is either "purple", "monkey", or "dishwasher", whereas I want it to match any titles that have those words somewhere in them. So I'd want it to match a thread called "How to search for a monkey in the forest" because it contains the word "monkey".
For that, I need to use LIKE, and I need to use the % wildcard either side of the search term so that it matches anything either side of the word (in this case, it would be
"How to search for a" and
"in the forest").