In this tutorial you will learn how to use the TOP option. The TOP option  is a exclusive T-SQL feature that allows you to limit the number or percentage of rows that your query returns.  A number is specified in the TOP option that declares how many row are displayed.

Setting Up

Before we start on the queries, let’s create  a table based on movies. Open SQL Server and click the New Query button. Inside the query we will create a table based on movies that will have a Title, Director, and ReleaseDate.

Next we will enter data into the table for us to work with. We will enter multiple values into the table in one query by defining the table and columns with the INSERT statement and then adding movie data with the SELECT statement.

TOP Option Keyword

Since we are going to select three movies with the TOP option we must specify it in the table followed by the columns to be displayed. After we do that we can detail from what table the columns are from, in this case Movies. We enter FROM Movies below the previous statement. and then below the FROM Movies statement we will use the ORDER BY statement to order the titles in descending order.

Run the query and you should see three titles displayed in descending order.

Thanks for reading and make sure to download the source files to get a better understanding of how the code works.

Download Source Files