Skip to main content
SQL • LESSON 08

Sorting & Limiting Results

How can we return only the top N records from a sorted dataset?

Intermediate2 Minutes160 XP
🤔 THE QUESTION

How can we return only the top N records from a sorted dataset?

💡 WHAT IS IT?

LIMIT constrains the number of rows returned by a query, ideal when paired with ORDER BY.

🎯 WHAT IS IT USED FOR?

Pagination, top 10 rankings, sampling large tables, and quick exploratory analysis.

💻 EXAMPLE
SELECT *
FROM employees
ORDER BY salary DESC
LIMIT 10;

🎯 Mission Objectives

Practice typing production-grade SQL code for Sorting & Limiting Results.

  • ORDER BY
  • LIMIT
  • Top-N analysis
  • Pagination