0

I've got a query splitting phrase to words and showing result:

SELECT (...) WHERE 'name' LIKE '%word1%' AND 'name' LIKE '%word2%' ... etc

My problem is that when I type 'word1 word2' than the results are different than for 'word2 word1'.

Why is that ? What causes it and how to fix it ?

3 Answers3

0

Use or condition

SELECT (...) WHERE 'name' LIKE '%word1%' or'name' LIKE '%word2%' ... etc
Sumit patel
  • 3,807
  • 9
  • 34
  • 61
0

change single quotes ' to backtick and use OR operator

SELECT (...) WHERE `name` LIKE '%word1%' OR `name` LIKE '%word2%' ... etc

Check this : https://stackoverflow.com/a/2122759/2815635

Community
  • 1
  • 1
Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109
0

why you separate them when you want 2 words in the same column?

Use this:

SELECT (...) WHERE 'name' LIKE '%word1%word2%' OR 'name' LIKE '%word2%word1%' ... etc
PSo
  • 958
  • 9
  • 25