Let’s say I have two tables:
Table 1 has the columns NOTE_ID (a unique key) and NOTE_BODY (a big text blurb).
Table 2 has the columns KEYWORD_ID (a unique key) and KEYWORD (a keyword).
I want to get a result set that tells me which keywords each NOTE_BODY contains, without nesting a bunch of loops. So ideally I would get a row for each NOTE_BODY-KEYWORD match.
What’s the right way to go about this? I’m unsure if a JOIN+LIKE’%%’ does the trick, or if I should be using full-text indexing. Any help much appreciated…
A full text indexing solution is the right way to do this, if you plan to have many rows. You could use MySQL’s native solution if you are using the MyISAM storage engine, but you could also consider the popular third-party search engines Sphinx and Apache Lucene.
On the other hand, a simple
INNER JOINwould have done the trick:Test case:
Result: