How a field's data type changes sorting

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

How a field's data type changes sorting

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A field stores the numbers 9 and 10 as TEXT. What order does ORDER BY ... ASC put them in?
A 10 then 9, because text sorts letter by letter
B 9 then 10, because 9 is smaller
2. The points field is an INTEGER. Which result does ORDER BY points ASC give?
A 10, 120, 9, 95
B 9, 10, 95, 120
3. Why would '2', '10' and '100' come out as '10', '100', '2' in a query?
A The field is a text type, so it compares character by character
B The field is an integer type, so it compares by value
4. A date field (type DATE) is sorted with ORDER BY orderDate ASC. What order do you get?
A Alphabetical order by month name
B Oldest date first, in time order
5. Which fix will make a price column sort as 2, 10, 100?
A Store the prices in a number field such as INTEGER or REAL
B Store the prices in a longer text field

Match the Pairs

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

Left columnRight column
1ORDER BY price ASC A9 < 10
2ORDER BY orderDate DESC BSorts rows by price from smallest to largest, using true number order when price is a number field
3In a text field, '10' sorts before '9' because text is compared one character at a time CSorts rows by date with the newest first, because a date field follows time order
4A number field sorts by true value, so 9 comes before 10 DText dates sort alphabetically, so '3 Feb' comes after '25 Jan'. Use a date field or the YYYY-MM-DD form so dates sort in time order.
5Storing stock as text, then using ORDER BY stock ASC and expecting 9 before 10 E'10' < '9'
6Storing dates as text like '3 Feb 2026' and then using ORDER BY orderDate FText sorts letter by letter, so '10' comes before '9'. The stock field should be a number data type such as integer.

Definitions

'10' < '9'

Fill in the Blanks

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

1.
SELECT name, price FROM products ORDER BY _____;
2.
SELECT firstName, points FROM students ORDER BY points ____;
3.
SELECT orderId, orderDate FROM orders ORDER BY _________;
4.
CREATE TABLE t (name TEXT, mark _______);
5.
SELECT * FROM orders ________ orderDate DESC;

Spot the Error

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

Question 1
A SELECT name, price
B FORM products
C ORDER BY price;
Question 2
A SELECT orderId, orderDate
B FROM orders
C ORDER orderDate ASC;
Question 3
A CREATE TABLE scores (
B points TEXT,
C name TEXT
D );
Question 4
A CREATE TABLE events (
B title TEXT,
C cost REAL,
D eventDate TEXT
E );
Question 5
A SELECT firstName, points
B FROM students;
C ORDER BY points DESC;

Answer Key

How a field's data type changes sorting
Section A: Quick Questions
Q1
A — 10 then 9, because text sorts letter by letter
Q2
B — 9, 10, 95, 120
Q3
A — The field is a text type, so it compares character by character
Q4
B — Oldest date first, in time order
Q5
A — Store the prices in a number field such as INTEGER or REAL
Section B: Match the Pairs
Q1
ORDER BY price ASC → Sorts rows by price from smallest to largest, using true number order when price is a number field
Q2
ORDER BY orderDate DESC → Sorts rows by date with the newest first, because a date field follows time order
Q3
In a text field, '10' sorts before '9' because text is compared one character at a time → '10' < '9'
Q4
A number field sorts by true value, so 9 comes before 10 → 9 < 10
Q5
Storing stock as text, then using ORDER BY stock ASC and expecting 9 before 10 → Text sorts letter by letter, so '10' comes before '9'. The stock field should be a number data type such as integer.
Q6
Storing dates as text like '3 Feb 2026' and then using ORDER BY orderDate → Text dates sort alphabetically, so '3 Feb' comes after '25 Jan'. Use a date field or the YYYY-MM-DD form so dates sort in time order.
Section C: Definitions
Q1
'10' < '9' — In a text field, '10' sorts before '9' because text sorts letter by letter. Number and date fields sort by true value, so 9 comes before 10 and dates follow time order.
Section D: Fill in the Blanks
Q1
SELECT name, price FROM products ORDER BY price;
Q2
SELECT firstName, points FROM students ORDER BY points DESC;
Q3
SELECT orderId, orderDate FROM orders ORDER BY orderDate;
Q4
CREATE TABLE t (name TEXT, mark INTEGER);
Q5
SELECT * FROM orders ORDER BY orderDate DESC;
Section E: Spot the Error
Q1
B — FORM is a typo. The keyword is FROM. The price field is a number type, so ORDER BY price sorts by true value (4 before 12).
Q2
C — The clause needs the word BY. It should be ORDER BY orderDate ASC; so the dates sort in time order.
Q3
B — If points is stored as TEXT, '10' sorts before '9' because text sorts letter by letter. It should be INTEGER so ORDER BY sorts by true value.
Q4
D — Dates stored as TEXT such as '10/3/2026' and '9/3/2026' sort letter by letter, not in time order. The field should use the DATE type.
Q5
B — The semicolon ends the statement too early, so ORDER BY is left on its own. Only put the semicolon at the very end, after ORDER BY points DESC.