0

I am trying to select some names which have words :similarq1, :similarq2, :similarq3 in them but I would like to not display the words which have the word "exclude" in them. I am trying the following query but adding WHERE wallname <> '%exclude%' does not seem to do anything.

$stmt = $pdo->prepare("SELECT * FROM walldb WHERE wallname <> '%exclude%' AND wallname LIKE :similarq1 OR wallname LIKE :similarq2 OR wallname LIKE :similarq3 LIMIT :simstat, :simlimt");

the suggested similar answers makes my query like this which does not work either:

$stmt = $pdo->prepare("SELECT * FROM walldb WHERE wallname <> '%exclude%' AND (wallname LIKE :similarq1 OR wallname LIKE :similarq2 OR wallname LIKE :similarq3) LIMIT :simstat, :simlimt");
Dharman
  • 30,962
  • 25
  • 85
  • 135
bl4ck120
  • 93
  • 2
  • 9
  • 2
    You might find [NOT LIKE](https://dev.mysql.com/doc/refman/8.0/en/string-comparison-functions.html#operator_not-like) useful. You may also want to group the ORs with parenthesis. See [How exactly does using OR in a MySQL statement differ with/without parentheses?](https://stackoverflow.com/questions/4872180/how-exactly-does-using-or-in-a-mysql-statement-differ-with-without-parentheses) and [OR WHERE and AND in mySQL Query](https://stackoverflow.com/questions/17750098/or-where-and-and-in-mysql-query) and [MySql query on combination of AND and OR](https://stackoverflow.com/questions/9640122/). – showdev Feb 24 '20 at 10:38
  • `NOT LIKE` did the trick! i understand why it was not working before now. Thankyou! :) – bl4ck120 Feb 24 '20 at 10:41
  • Regarding using wildcards to compare equality, perhaps a better reference would be [How to perform string does not equal](https://stackoverflow.com/questions/16324504/sql-how-to-perform-string-does-not-equal/16324521). – showdev Feb 24 '20 at 10:41

0 Answers0