bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL Tutorial
SQL•SQL Tutorial

SQL NOT Operator

Concept visual

SQL NOT Operator

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

The NOT Operator

The NOT

operator is used in the WHERE

clause to return all records that DO NOT match the specified criteria. It reverses the result of a condition from true to false and vice-versa.

The following SQL selects all customers that are NOT from Spain:

Example

Select only the customers that are NOT from Spain:

SELECT * FROM Customers
WHERE NOT Country = 'Spain';

In the example above, the NOT operator is used in combination with the = operator.

The NOT

operator is also used in combination with other operators to exclude data, such as: NOT LIKE NOT BETWEEN NOT IN IS NOT NULL

Not Exists

NOT Syntax

Select

column1, column2, ...

From

table_name

Where Not

condition

;

Demo Database

Below is a selection from the

Customers table used in the examples:

CustomerID

CustomerName

ContactName

Address

City

PostalCode

Country

Alfreds Futterkiste

Maria Anders

Obere Str. 57

Berlin

12209

Germany

Ana Trujillo Emparedados y helados

Ana Trujillo

Avda. de la Constitución 2222 México D.F. 05021

Previous

SQL OR Operator

Next

SQL INSERT INTO Statement