MODULE 2 · Shaping results
Reading · 15 min
Sorting results
Sorting results
Tables do not promise a useful display order. ORDER BY makes the requested order part of the query rather than an accident of storage.
Learning objectives
- Sort ascending and descending
- Use a secondary sort
Order results intentionally with ORDER BY. Focus on explaining each decision in your own words before relying on a pattern or shortcut.
Example
SELECT name, created_at
FROM customers
ORDER BY created_at DESC, name ASC;Summary
KEY TAKEAWAYS
- ORDER BY makes result order explicit.
- Secondary ordering makes ties predictable.
Reading material
Sorting results practice prompt
Use the exercise in this lesson to check your understanding.
Your progress is saved on this device. Sign in to keep it across devices.
