TOP clause in SQL Server is used to specify the number of rows to be returned in a
It can be used in conjunction with the
ORDER BY clause to return the top N records based on a specific sort order.
SELECT TOP number column_name(s) FROM table_name
SELECT TOP percent column_name(s) FROM table_name
For example, the following query would return the top 10 records from the "Employees" table, sorted by last name in ascending order:
SELECT TOP 10 *
ORDER BY LastName ASC;
You can also use the
TOP clause with a percentage value, in which case it will return the specified percentage of rows.
For example, the following query would return the top 20% of records from the "Employees" table, sorted by hire date in descending order:
SELECT TOP 20 PERCENT *
ORDER BY HireDate DESC;
It's important to note that the
TOP clause is only available in the
SELECT statement and it can't be used in an
TOP clause is not a standard SQL statement. It's specific to SQL Server.