Search code examples
mysqlsqlsql-like

Check if a list of other strings is %LIKE% another string


Is there a short way to check if a list of strings is %LIKE% a given string?

For example:

book animal a

Would all satisfy this condition for "A Book about Animals"?

I know that I could write out Title Like '%book%' AND '%animal%' LIKE Title, etc. but that seems unwieldy.

I'm using this for an autocomplete, where I return results where every word is in the result.


Solution

  • mate... make the searchable columns into "fulltext" colums and then do

    SELECT * FROM books WHERE MATCH(fulltext_column) AGAINST('animal book a')

    best way. :) see http://devzone.zend.com/article/1304