Weld logo
SQL TUTORIAL • LESSON 8, Filtering

Filtering when conditions are NOT fulfilled

As you might remember, you can use the != statement to filter out values that are not equal to the condition, but as with = this will only work for exact values. So, if you want to filter out based on values that are not exact, you should use the NOT statement instead. Using the product list to create a list of all products in the Order line table except the ones where Cheese is included could be queried like this:

1select
2    *
3from
4    w {{raw.e_commerce_sample.webshop_order_line}}
5where
6    product not like '%Cheese%'

Exercise 5: Find all the customers with First Names not starting with ‘S’

This exercise also uses the Customer table. This time try to write a query that does the opposite of last time: find all the customers with first names starting with everything other than S. If you run your query, it should give a result like this:

In SQL there are often many means to an end, so you’ll usually be able to get the required result by writing different variations of the same query. A simple way to solve the exercise above would be to write a query like this:

1select
2    *
3from
4    w {{raw.e_commerce_sample.webshop_order_line}}
5where
6    product not like '%Cheese%'

Next up

Introduction to columns

Go to lesson
Weld logo

Tired of scattered data? Sync your data in minutes with our AI-powered ETL platform. Seamlessly connect all your apps, files, and databases.

Backed by leading investors
Frontline logoCherry logoInnnovation Fund logo
Twitter LogoLinkedIn Logo
GDPR logoSOC2
© 2024 Weld. All rights reserved.