Search code examples
mysqlsearchtextsql-like

MySQL multi-word search with one query


I'm wanting to do an ANDing or ORing in my MySQL query, but the LIMIT needs to be the same regardless.

eg. SELECTION * FROM table WHERE text LIKE %word1 OR word2 OR word3% LIMIT 10

I'd like this to work the same way it does on Twitter.


Solution

  • SELECT * FROM table
    WHERE (text LIKE %word1%) OR (text LIKE %word2%) 
    OR (text LIKE %word3%) LIMIT 10