SELECT TOP
Published Jan 30, 2023Updated May 15, 2024
Contribute to Docs
The SELECT TOP
command returns a specified number of rows from the top of the result.
Syntax
This command is used to select the initial rows from a table, limiting the result to a specified number, represented here by n
:
SELECT TOP (n) column_name(s)FROM table_name;
Where column_name(s)
is a comma delimited list of columns from the table table_name
.
The command can also be used with PERCENT
to limit the result to the top n
percent of rows:
SELECT TOP (n) PERCENT column_name(s)
FROM table_name;
Examples
The following query selects all columns from the top 5 rows of the books
table:
SELECT TOP (5) *FROM books;
The next query selects the top 25% of rows from the movies
table, under just the movie_titles
column:
SELECT TOP (25) PERCENT movie_titlesFROM movies;
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.