The AND keyword
Part of the Fundamentals section of Coddy's SQL journey — lesson 6 of 72.
The AND keyword means that both conditions must be true; if either one of them is not, then the condition will not be met.
For example here is a <b>people</b> table:
| name | age | gender |
|---|---|---|
| Joas | 13 | male |
| Holwa | 17 | male |
| Nohlas | 24 | female |
| Polar | 23 | male |
| Loopa | 18 | female |
The following query:
SELECT *
FROM people
WHERE gender = "female" AND age < 20means that we are looking for all records that the gender is "female" and the age is less than 20.
This will be the result:
| name | age | gender |
|---|---|---|
| Loopa | 18 | female |
Note: In SQL, string values can be written with either double quotes "female" or single quotes 'female' — both are accepted in most SQL databases.
Challenge
EasyAvailable tables and columns:
people:name,age,statusTable: people
name age status Charles 28 employed Fatima 38 unemployed Eric 11 unemployed Diya 44 employed Hanna 22 employed Ali 20 unemployed Gabriel 37 employed Beatriz 17 employed Troy 29 unemployed Angelica 32 employed
Fetch all of the people from the people table who are between the ages of 20 and 28 (including 20 and 28).
Cheat sheet
The AND keyword requires both conditions to be true:
SELECT *
FROM people
WHERE gender = "female" AND age < 20This returns records where the person is female AND under 20 years old.
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