Query criteria with comparison operators

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

Query criteria with comparison operators

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which criterion shows only students in Year 7?
A WHERE Year = 7
B WHERE Year <> 7
2. Which criterion shows students who scored MORE than 80 (80 is not included)?
A WHERE Score >= 80
B WHERE Score > 80
3. What does the operator <> mean in a query criterion?
A Not equal to
B Less than or equal to
4. Which criterion correctly finds pets whose Type is dog?
A WHERE Type = dog
B WHERE Type = "dog"
5. A query uses WHERE Age <= 13. Which student would be shown?
A A student who is 13
B A student who is 14

Match the Pairs

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

Left columnRight column
1WHERE Score > 80 AShows only records where the Year is not equal to 7
2WHERE Year <> 7 BShows only records where the Score is greater than 80
3Show only students who are in Year 8 (a number criterion) CWHERE Year = 8
4Text criteria must be put inside quotes DThe text value Blue is missing its quotes. It should be WHERE Team = "Blue".
5WHERE Team = Blue EThe >= operator also includes 80. To get only scores above 80, use > instead: WHERE Score > 80.
6WHERE Score >= 80 (to find scores above 80 only) FWHERE Team = "Blue"

Definitions

WHERE Score > 80

Fill in the Blanks

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

1.
SELECT Name, Score FROM Students _____ Score > 80
2.
SELECT Name FROM Students WHERE House _ "Red"
3.
SELECT Name FROM Students WHERE Score __ 50
4.
SELECT Name FROM Students WHERE Score __ 80
5.
SELECT Name FROM Students WHERE Age __ 12

Spot the Error

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

Question 1
A SELECT Name FROM Students
B WHERE Score < 80;
C -- Only Score above 80 shows
Question 2
A SELECT * FROM Students
B WHERE Year == 7;
C -- Only Year 7 records
Question 3
A SELECT Name, Score
B FROM Results
C WHERE Score > 50;
D -- Pass mark is 50 or more
Question 4
A SELECT Name
B FROM Students
C WHERE Town = Cairns;
Question 5
A SELECT * FROM Pets
B WHERE Type >< 'Dog';
C -- Every pet except dogs

Answer Key

Query criteria with comparison operators
Section A: Quick Questions
Q1
A — WHERE Year = 7
Q2
B — WHERE Score > 80
Q3
A — Not equal to
Q4
B — WHERE Type = "dog"
Q5
A — A student who is 13
Section B: Match the Pairs
Q1
WHERE Score > 80 → Shows only records where the Score is greater than 80
Q2
WHERE Year <> 7 → Shows only records where the Year is not equal to 7
Q3
Show only students who are in Year 8 (a number criterion) → WHERE Year = 8
Q4
Text criteria must be put inside quotes → WHERE Team = "Blue"
Q5
WHERE Team = Blue → The text value Blue is missing its quotes. It should be WHERE Team = "Blue".
Q6
WHERE Score >= 80 (to find scores above 80 only) → The >= operator also includes 80. To get only scores above 80, use > instead: WHERE Score > 80.
Section C: Definitions
Q1
WHERE Score > 80 — A criterion that limits a query to records where the condition is true, so only Score values above 80 are shown. Compare with =, <>, <, >, <=, >=. Text goes in quotes.
Section D: Fill in the Blanks
Q1
SELECT Name, Score FROM Students WHERE Score > 80
Q2
SELECT Name FROM Students WHERE House = "Red"
Q3
SELECT Name FROM Students WHERE Score <> 50
Q4
SELECT Name FROM Students WHERE Score >= 80
Q5
SELECT Name FROM Students WHERE Age <= 12
Section E: Spot the Error
Q1
B — The comment says only Score values above 80 should show, but < keeps scores below 80. It should be WHERE Score > 80;
Q2
B — A query criterion uses a single = to test for equal values. Double == is not used in a query. It should be WHERE Year = 7;
Q3
C — The pass mark is 50 or more, so students who scored exactly 50 must be included. > leaves them out. It should be WHERE Score >= 50;
Q4
C — Text criteria must go in quotes. Without quotes, Cairns looks like a field name. It should be WHERE Town = 'Cairns';
Q5
B — There is no >< operator. 'Not equal to' is written <>. It should be WHERE Type <> 'Dog';