Menu
Coddy logo textTech

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:

nameagegender
Joas13male
Holwa17male
Nohlas24female
Polar23male
Loopa18female

 

The following query:

SELECT * 
FROM people
WHERE gender = "female" AND age < 20

means that we are looking for all records that the gender is "female" and the age is less than 20.

This will be the result:

nameagegender
Loopa18female

 

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 icon

Challenge

Easy

Available tables and columns:

  • people: name, age, status

Table: people

nameagestatus
Charles28employed
Fatima38unemployed
Eric11unemployed
Diya44employed
Hanna22employed
Ali20unemployed
Gabriel37employed
Beatriz17employed
Troy29unemployed
Angelica32employed

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 < 20

This returns records where the person is female AND under 20 years old.

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