SQL tutorial •
Lesson
8
,
Filtering

Filtering when conditions are NOT fulfilled

As you might remember, you can use the <span class="code">!=</span> statement to filter out values that are not equal to the condition, but as with <span class="code">=</span> 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 <span class="code">NOT</span> statement instead. Using the product list to create a list of all products in the <span class="code">Order line</span> table except the ones where Cheese is included could be queried like this:

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

This exercise also uses the <span class="code">Customer</span> 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:

Next up:
Introduction to columns