I came across a forum post where someone wanted to use SQL NOT LIKE with multiple values.
They were trying to exclude multiple values from the SQL query, but they were needing to use wildcards.
If you wanted to just filter values without wildcards, you would use the following query.
select * from table1 where column1 not in ('value1','value2','value3');
The only problem was that they needed to compare using the LIKE operator.
It would be nice if you could just stick some wildcards in the in clause like this:
where column1 not in ('%value1%','%value2%','%value3%')
But, you can’t stick a wildcard inside of the IN clause. So, here is the easiest solution.
select * from table1 where column1 not like '%value1%' and column1 not like '%value2%' and column1 not like'%value3%';
If you want to play around with the Boolean logic, you rearrange the query like this.
select * from table1 where not (column1 like '%value1%' or column1 like '%value2%' or column1 like'%value3%');
What happens if you don’t put those parenthesis in?
Here are a few other posts you might enjoy:
SQL Wildcards | SQL Multiple Filter | How to use the SQL In Statement with Subquery
You can visit me at any of the following:
SQL Training Online: https://www.sqltrainingonline.com