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:
| name | age | gender |
|---|---|---|
| Joas | 13 | male |
| Holwa | 17 | male |
| Nohlas | 24 | female |
| Polar | 23 | male |
| Loopa | 18 | female |
SELECT *
FROM people
WHERE NOT gender = 'male'This will be the result:
| name | age | gender |
|---|---|---|
| Nohlas | 24 | female |
| Loopa | 18 | female |
The NOT keyword basically flips the condition. For example the following queries are the same:
WHERE age > 20WHERE NOT age <= 20Challenge
EasyAvailable 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 > 20WHERE NOT age <= 20Try it yourself
SELECT *
FROM PEOPLE
-- Write your code below
WHEREThis lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns