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.
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.