SQL WHERE conditions

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

SQL WHERE conditions

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which query keeps only students who are 15 or older?
A SELECT * FROM students WHERE age >= 15;
B SELECT * FROM students WHERE age => 15;
2. Which WHERE condition correctly matches students who live in Perth?
A WHERE town = Perth
B WHERE town = 'Perth'
3. True or false: WHERE keeps only the rows that meet the condition.
A False
B True
4. Which query finds students in Year 10 AND aged 16 or over?
A WHERE year = 10 AND age >= 16
B WHERE year = 10 OR age >= 16
5. Which query finds students who play either 'Netball' or 'Soccer'?
A WHERE sport = 'Netball' OR sport = 'Soccer'
B WHERE sport = 'Netball' AND sport = 'Soccer'

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1SELECT * FROM students WHERE age >= 15; AThe comparison operator is written backwards. It should be >= not =>.
2WHERE town = 'Perth' OR town = 'Darwin' BWHERE subject = 'Maths'
3Text values in a WHERE condition must be wrapped in quotes CThe text value Perth is missing quotes. It should be 'Perth'.
4AND keeps a row only when both conditions are true DKeeps rows where the town is either Perth or Darwin
5SELECT * FROM students WHERE town = Perth; EShows only the students who are 15 or older
6SELECT * FROM students WHERE age => 15; FWHERE age >= 15 AND year = 10

Definitions

WHERE

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
SELECT * FROM students _____ age >= 15;
2.
SELECT name FROM students WHERE age __ 15;
3.
SELECT * FROM students WHERE town = 'Perth' ___ age >= 15;
4.
SELECT name FROM students WHERE town = 'Perth' __ town = 'Hobart';
5.
SELECT title FROM books WHERE price _ 20;

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A SELECT name FROM pets WHILE
B age > 3 AND type = 'dog'
C ORDER BY name;
Question 2
A SELECT name, town
B FROM students
C WHERE town = 'Perth'
D AND age => 15;
Question 3
A SELECT name
B FROM players
C WHERE score > 50
D AND team = Reds;
Question 4
A SELECT * movies
B WHERE year >= 2010
C AND genre = 'comedy';
Question 5
A SELECT name FROM staff
B WHERE role == 'Tutor'
C OR role = 'Coach';

Answer Key

SQL WHERE conditions
Section A: Quick Questions
Q1
A — SELECT * FROM students WHERE age >= 15;
Q2
B — WHERE town = 'Perth'
Q3
B — True
Q4
A — WHERE year = 10 AND age >= 16
Q5
A — WHERE sport = 'Netball' OR sport = 'Soccer'
Section B: Match the Pairs
Q1
SELECT * FROM students WHERE age >= 15; → Shows only the students who are 15 or older
Q2
WHERE town = 'Perth' OR town = 'Darwin' → Keeps rows where the town is either Perth or Darwin
Q3
Text values in a WHERE condition must be wrapped in quotes → WHERE subject = 'Maths'
Q4
AND keeps a row only when both conditions are true → WHERE age >= 15 AND year = 10
Q5
SELECT * FROM students WHERE town = Perth; → The text value Perth is missing quotes. It should be 'Perth'.
Q6
SELECT * FROM students WHERE age => 15; → The comparison operator is written backwards. It should be >= not =>.
Section C: Definitions
Q1
WHERE — An SQL clause that keeps only the rows meeting a condition, such as WHERE age >= 15 or WHERE town = 'Perth'. Text goes in quotes, and AND or OR can combine conditions.
Section D: Fill in the Blanks
Q1
SELECT * FROM students WHERE age >= 15;
Q2
SELECT name FROM students WHERE age >= 15;
Q3
SELECT * FROM students WHERE town = 'Perth' AND age >= 15;
Q4
SELECT name FROM students WHERE town = 'Perth' OR town = 'Hobart';
Q5
SELECT title FROM books WHERE price < 20;
Section E: Spot the Error
Q1
A — WHILE is not an SQL clause. The keyword that filters rows by a condition is WHERE, so the line should be SELECT name FROM pets WHERE.
Q2
D — => is not a valid comparison operator. 'Greater than or equal to' is written >=, so the line should be AND age >= 15;
Q3
D — Text values must be in quotes. Without them SQL treats Reds as a column name. It should be AND team = 'Reds';
Q4
A — The FROM keyword is missing, so SQL does not know which table to read. It should be SELECT * FROM movies.
Q5
B — SQL tests equality with a single = sign, not ==. The line should be WHERE role = 'Tutor'.