ORDER BY sorts the result, and LIMIT returns just the first N rows — together they answer "top 10" style questions and make output readable.
ORDER BY
SELECT name, package FROM studentsORDER BY package DESC; -- highest first (ASC is the default)SELECT * FROM studentsORDER BY programme ASC, package DESC; -- by two keys
LIMIT & pagination
SELECT name, package FROM studentsORDER BY package DESCLIMIT 10; -- top 10SELECT * FROM studentsORDER BY id LIMIT 10 OFFSET 20; -- page 3 of 10-row pages
Key takeaways
- 01ORDER BY sorts the result; ASC (default) or DESC, and by multiple keys.
- 02LIMIT returns the first N rows — pair it with ORDER BY for meaningful "top N".
- 03OFFSET skips rows for pagination.
- 04LIMIT syntax varies by database (TOP / FETCH FIRST elsewhere).
