Sort results by number of matching words I have a table (called sentences) in which I have some sentences. I want people to be able to search it with multiple words, which would make the SQL query look like this:
SELECT content FROM sentences WHERE content LIKE &quot;%&lt;word1&gt;%&quot;
                                 OR content LIKE &quot;%&lt;word2&gt;%&quot;
                                 OR content LIKE &quot;%&lt;word3&gt;%&quot; etc... ;

How can I sort the results by the number of occurrences of different words, the most matching sentence comes first, etc...?
Add a fulltext index on content and use &quot;match&quot;, as in
SELECT *, match(content)
  against ('you surround' IN NATURAL LANGUAGE MODE) as score
  FROM Sentence
  Order by score desc

See this fiddle