SQL SELECT WHERE field contains words

Created by mvpLinked to 9.3m issues across 77 teams

tl;dr

First, if you want to include any of the words, use this query:

SELECT * FROM mytable WHERE column1 LIKE '%word1%' OR column1 LIKE '%word2%' OR column1 LIKE '%word3%'

If you need all of the words to be present, use this query instead:

SELECT * FROM mytable WHERE column1 LIKE '%word1%' AND column1 LIKE '%word2%' AND column1 LIKE '%word3%'

Finally, if you're looking for something faster, you may need to look into full text search, which is specific to each database type.