Retrieving data from a database is only useful if the results are clear and meaningful. In IB Computer Science, students are expected to understand not just how to select data, but also how to sort and control the output. This is where ORDER BY and LIMIT become essential.
Examiners often assess whether students understand what these clauses do, rather than just where they appear in a query.
Why Sorting Results Matters
Databases often contain:
- Hundreds or thousands of records
- Data in no meaningful order
Without sorting:
- Results may appear random
- Important information may be hard to identify
Sorting allows users to:
- Find highest or lowest values
- Organise data alphabetically
- Make results easier to interpret
In IB terms, sorting improves data usability, not data accuracy.
What Is ORDER BY?
The ORDER BY clause is used to sort query results.
It controls:
- The order in which records are displayed
ORDER BY does not change the data stored in the database — it only affects how results appear.
Sorting in Ascending and Descending Order
ORDER BY can sort data in two directions:
- Ascending (ASC)
- Default order
- Alphabetical (A–Z)
