Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Using the NOT Operator | Advanced Data Filtering
Introduction to SQL
course content

Kursusindhold

Introduction to SQL

Introduction to SQL

1. Retrieving Data
2. Sorting Retrieved Data
3. Filtering Data
4. Advanced Data Filtering
5. Aggregate Functions

book
Using the NOT Operator

In order to cancel the condition, you need to use the keyword NOT.

The NOT operator is essential when you want to exclude certain records from your query results. It allows you to specify conditions that should not be met, effectively filtering out unwanted data. This can be particularly useful in scenarios where you need to focus on a subset of data that does not meet specific criteria.

First, let’s look at the syntax:

sql

Now let's look at the example:

123
SELECT name, capital FROM country WHERE NOT continent='Asia';
copy

Explanation: The NOT operator rejects the condition here; hence, it matches the continent to anything that is not Asia.

Here is the country table we are working with:

Opgave

Swipe to start coding

Write an SQL query to get the name and capital columns from the country table (please retrieve these columns in this order). These countries must be not from the 'South America' continent.

Note

Pay attention to the fact that the names of the continents begin with a capital letter and not a lowercase one; this is very important.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 5
toggle bottom row

book
Using the NOT Operator

In order to cancel the condition, you need to use the keyword NOT.

The NOT operator is essential when you want to exclude certain records from your query results. It allows you to specify conditions that should not be met, effectively filtering out unwanted data. This can be particularly useful in scenarios where you need to focus on a subset of data that does not meet specific criteria.

First, let’s look at the syntax:

sql

Now let's look at the example:

123
SELECT name, capital FROM country WHERE NOT continent='Asia';
copy

Explanation: The NOT operator rejects the condition here; hence, it matches the continent to anything that is not Asia.

Here is the country table we are working with:

Opgave

Swipe to start coding

Write an SQL query to get the name and capital columns from the country table (please retrieve these columns in this order). These countries must be not from the 'South America' continent.

Note

Pay attention to the fact that the names of the continents begin with a capital letter and not a lowercase one; this is very important.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 5
Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Vi beklager, at noget gik galt. Hvad skete der?
some-alt