← ACARA Digital Technologies Years 7–8

How a field's data type changes sorting

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.

Understanding How a field's data type changes sorting in ACARA Digital Technologies Years 7–8

What it does: Text compares the first characters '1' and '9', and '1' comes first, so '10' sorts before '9'. With an integer or floating point field the whole value is compared, so 9 is smaller than 10 and sorts first. Only text fields sort letter by letter. Integer fields would give 2, 10, 100. A real date field sorts by time. Earlier dates come before later dates. YYYY-MM-DD is written biggest unit first, so letter-by-letter sorting matches time order. Formats like DD/MM/YYYY would not. ORDER BY uses the field's data type. Numbers stored as text will sort in the wrong order.

Common mistakes: 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). The clause needs the word BY. It should be ORDER BY orderDate ASC; so the dates sort in time order.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 365–411) and word search (Modules 331–411).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A field stores the numbers 9 and 10 as TEXT. What order does ORDER BY ... ASC put them in?
9 then 10, because 9 is smaller10 then 9, because text sorts letter by letter
Matches
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.
Applying
Meanings
Term
'10' < '9'
Meaning
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.
Practice
SELECT firstName, points
Testing
Gaps
ORDER BY ;
Check Answer
Spots
1SELECT name, price
2FORM products

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Space Turtle' badge — Speed in Zero-G, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

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
Text compares one character at a time. '1' comes before '9', so '10' sorts before '9'.
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 ✓
Integer fields sort by true value, so smaller numbers come first. The text-style order is the wrong one here.
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
Only text fields sort letter by letter. Integer fields would give 2, 10, 100.
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 ✓
A real date field sorts by time. Earlier dates come before later dates.
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
The data type decides how values are compared. A number type sorts by value, but a longer text field still sorts letter by letter.

Match the Pairs

ORDER BY price ASC → Sorts rows by price from smallest to largest, using true number order when price is a number field
ORDER BY orderDate DESC → Sorts rows by date with the newest first, because a date field follows time order
In a text field, '10' sorts before '9' because text is compared one character at a time → '10' < '9'
A number field sorts by true value, so 9 comes before 10 → 9 < 10
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.
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.

Key Term

'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.

Fill in the Blanks

1. SELECT name, price FROM products ORDER BY price;
Hint: Type the number field to sort by, so 4 comes before 25 by true value.
2. SELECT firstName, points FROM students ORDER BY points DESC;
Hint: Type the keyword that puts the biggest number first.
3. SELECT orderId, orderDate FROM orders ORDER BY orderDate;
Hint: Type the date field so the rows come out in time order.
4. CREATE TABLE t (name TEXT, mark INTEGER);
Hint: Type the whole-number data type so 9 sorts before 10.
5. SELECT * FROM orders ORDER BY orderDate DESC;
Hint: Type the two-word clause that sorts the results, here newest date first.

Spot the Error

Question 1
A SELECT name, price
B FORM products
C ORDER BY price;
Line 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).
Question 2
A SELECT orderId, orderDate
B FROM orders
C ORDER orderDate ASC;
Line C — The clause needs the word BY. It should be ORDER BY orderDate ASC; so the dates sort in time order.
Question 3
A CREATE TABLE scores (
B points TEXT,
C name TEXT
D );
Line 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.
Question 4
A CREATE TABLE events (
B title TEXT,
C cost REAL,
D eventDate TEXT
E );
Line 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.
Question 5
A SELECT firstName, points
B FROM students;
C ORDER BY points DESC;
Line 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.

Student with a class code? Join your class →