Beginner

22. TOP

Learn how the TOP keyword limits the number of rows returned in SQL Server.

📘 Lesson 22 of 728 ⏱ 7 min 🎯 Beginner

TOP is a SQL Server feature used to limit the number or percentage of rows returned by a query. It is commonly used when working with Microsoft SQL Server. TOP can be especially useful when identifying a small number of records such as the highest salaries, largest transactions, or top-performing products.

Different database systems use different syntax for limiting query results. Understanding TOP is important when working with SQL Server, which is widely used in business and enterprise environments.

Suppose a company wants to identify the 10 employees with the highest salaries. TOP can be combined with ORDER BY to return those employees.

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

TOP is commonly used in SQL Server for ranking reports, sales analysis, employee analysis, financial reporting, and dashboard queries.

  • TOP limits the number of rows returned.
  • TOP is commonly associated with SQL Server.
  • TOP can be combined with ORDER BY.
  • TOP can return a percentage of rows.
  • TOP does not delete records from the table.
What is TOP in SQL?

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

How can you find the top 10 salaries?

Use TOP 10 together with ORDER BY Salary DESC.

Have you finished this lesson?

Introduction to SQL – All Lessons