I have a MySQL database table that has a "word" column with space-delimited values. For example:
one two three four five
So given the record above, I want to find other records that contain one or more of those space-delimited values, and order the results by most number of relevant matches. How can I go about achieving this?
For example:
one two six seven eight
three nine ten eight seven
one two three six seven
one two three four ten
six seven eight nine ten
I would want the following returned:
one two three four ten --4 matching values
one two three six seven --3 matching values
one two six seven eight --2 matching values
three nine ten eight seven --1 matching value
This is the query I'm using so far:
SELECT * from MyTable WHERE words like '%one%' OR words like '%two%' OR words like '%three%' OR words like '%four%' OR words like '%five%'
But that only selects results that share one or more of the words. How can I keep track of how many matches there are and order the results in terms of that?