The OR keyword
Part of the Fundamentals section of Coddy's SQL journey — lesson 7 of 72.
The OR keyword means that we want one of the conditions to be true.
For example consider the following <b>people</b> table:
| name | age | gender |
|---|---|---|
| Joas | 13 | male |
| Holwa | 17 | male |
| Nohlas | 24 | female |
| Polar | 23 | male |
| Loopa | 18 | female |
SELECT *
FROM people
WHERE gender = 'female' OR age < 20This query means that we are looking for all records that either the gender is female or the age is less than 20.
This will be the result:
| name | age | gender |
|---|---|---|
| Joas | 13 | male |
| Holwa | 17 | male |
| Nohlas | 24 | female |
| Loopa | 18 | female |
Challenge
EasyAvailable tables and columns:
<b>people</b>:<b>age</b>,<b>status</b>
Fetch all of the people who are either under age of 20 or above age 28 (not including 20 and not including 28).
Cheat sheet
The OR keyword returns records where at least one condition is true:
SELECT *
FROM people
WHERE gender = 'female' OR age < 20Returns rows where gender = 'female' or age < 20 (or both).
Try 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