Module 1 · Tables, types and the question you are actually asking

Sorting, limits, and the rows that move between runs

In this lesson

  • 7 min read
  • 6 reading sections
  • Knowledge check
  • Lesson 7 of 12 in this chapter

This chapter’s goalSet up a working database on your own machine, read an unfamiliar schema well enough to say what one row of each table means and which columns join to which, and state the grain of any result you are about to compute before you compute it.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 7Free · no account needed
Lesson steps

A query without ORDER BY has no order

This surprises people, so state it plainly: unless you write ORDER BY, the database is free to return rows in any order it likes, and it will change its mind. The same query can come back in a different order after an index is added, after rows are updated, or when the planner decides to use several CPU cores.

It usually looks stable, which is what makes it dangerous. A report that has been fine for eight months starts showing a different “top 10” because someone ran a maintenance job.

SQL
SELECT full_name FROM students LIMIT 10;            -- ten arbitrary students
SELECT full_name FROM students ORDER BY id LIMIT 10; -- the same ten, always

LIMIT without ORDER BY does not mean “the first ten”. It means “any ten, stop early”.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the Building Apps with AI exam.

Stuck on something?Ask Divya, your AI tutor

How to cite: Addaly (2026) ‘Sorting, limits, and the rows that move between runs’, in Data, SQL and Getting to the Answer. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/data-and-sql/sorting-limits-and-ties (Accessed: 29 November 2026).