Beginner

396. TOP Clause

Learn how SQL Server uses TOP to restrict the number of rows returned.

📘 Lesson 396 of 728 ⏱ 8 min 🎯 Beginner

TOP is a SQL Server feature used to return only a specified number or percentage of rows from a query result.

TOP is important for analysts working with Microsoft SQL Server and is commonly used for top-N analysis.

Return the 10 highest-paid employees.

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

TOP is used in SQL Server for ranking reports, top-performing products, highest-value customers, and quick data previews.

  • TOP is commonly used in SQL Server.
  • It limits the number of returned rows.
  • TOP works well with ORDER BY for top-N analysis.
  • TOP can also support percentages in SQL Server.
  • Other databases may use different syntax.
What is TOP used for?

TOP limits the number of rows returned by a SQL Server query.

Why combine TOP with ORDER BY?

ORDER BY determines which rows are highest or lowest before TOP selects the required number of rows.

Have you finished this lesson?

Introduction to SQL – All Lessons