How to Limit Query Results for MS SQL Server Databases Using Top

MS SQL Server provides the top syntax that can be used in SQL select queries to limit the records returned from a query. This is especially useful when querying very large tables in cases where the user only cares about a subset of the records. Listed below are examples of how to use the top syntax.

Example 1: Returning the first 100 rows from a table called employee:

select top 100 * from employee

Example 2: Returning the top 20% of rows from a table called employee:

select top 20 percent * from employee