Beginner

159. TOP Clause

Learn how TOP limits the number of rows returned in SQL Server and some related systems.

📘 Lesson 159 of 728 ⏱ 8 min 🎯 Beginner

TOP is a SQL Server feature used to limit the number or percentage of rows returned by a query.

TOP is useful when working with SQL Server and when only a limited number of records are required.

A manager may want to see the top 10 highest-paid employees.

SQL
SELECT TOP 10
    EmployeeName,
    Salary
FROM Employees
ORDER BY Salary DESC;

TOP is commonly used in SQL Server reporting, analysis, testing, and ranking queries.

  • TOP limits returned rows.
  • It is commonly associated with SQL Server.
  • TOP can be combined with ORDER BY.
  • It can be used with percentages in supported syntax.
  • Other databases may use different row-limiting syntax.
What is TOP in SQL?

TOP is used in SQL Server to limit the number or percentage of rows returned by a query.

Why combine TOP with ORDER BY?

ORDER BY ensures that the selected top rows are based on a defined sorting order.

Have you finished this lesson?

Introduction to SQL – All Lessons