Back to Blog

Beginning SQL

SQL Not Like with Multiple Values

Filter with SQL NOT LIKE for pattern exclusions. Learn to exclude multiple patterns and combine with OR operator in SQL Server queries.

2 min read

Last updated on

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%');

SQL Not Like with Multiple Values

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: /

Twitter: http://www.twitter.com/sql_by_joey

Google+:

LinkedIn: http://www.linkedin.com/in/joeyblue

Facebook: http://www.facebook.com/sqltrainingonline

About Joey Blue

Joey Blue teaches practical data skills that companies actually use. With 25+ years of experience solving real data problems for Fortune 500 companies, he's helped 152,000+ students learn SQL, Power BI, reporting, and modern analytics—cutting straight to what works.