Lewis Smith Lewis Smith - 2 months ago 8
MySQL Question

Select * but no results containing "This"

Is there a way in sql to write a query that returns all results other than ones containing "This"

So in my mind it would look something like this but I know it doesn't work

$sql = 'SELECT * FROM tablename EXCLUDING WHERE col1 = This'


I know the above won't work, but is there something similar that will, can't seem to find anything on here to help

Answer

Try using NOT LIKE:

$sql = 'SELECT * FROM tablename WHERE col1 NOT LIKE "%This%"'

From w3resource:

MySQL NOT LIKE is used to exclude those rows which are matching the criterion followed by LIKE operator.