Menu
Coddy logo textTech

The NOT keyword

Part of the Fundamentals section of Coddy's SQL journey — lesson 8 of 72.

The NOT keyword means that we don't want the condition to be met.

For example consider the following <strong>people</strong> table:

nameagegender
Joas13male
Holwa17male
Nohlas24female
Polar23male
Loopa18female
SELECT * 
FROM people
WHERE NOT gender = 'male'

This will be the result:

nameagegender
Nohlas24female
Loopa18female

The NOT keyword basically flips the condition. For example the following queries are the same:

WHERE age > 20
WHERE NOT age <= 20
challenge icon

Challenge

Easy

Available tables and columns:

  • <strong>people</strong>: <strong>name</strong>, <strong>age</strong>, <strong>status</strong>

Fetch all of the people where the status is NOT retired

Cheat sheet

The NOT keyword is used to negate a condition, meaning we don't want the condition to be met.

SELECT * 
FROM people
WHERE NOT gender = 'male'

The NOT keyword flips the condition. These queries are equivalent:

WHERE age > 20
WHERE NOT age <= 20

Try it yourself

SELECT *
FROM PEOPLE
-- Write your code below
WHERE
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals