From the course: Querying Microsoft SQL Server 2019

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Limit results with TOP

Limit results with TOP - SQL Server Tutorial

From the course: Querying Microsoft SQL Server 2019

Start my 1-month free trial

Limit results with TOP

- [Instructor] Normally when you run a SELECT query, all of the records that match your filtering criteria are returned from the database. There is a way to limit how many records are returned using the TOP clause. In the AdventureWorks database in the Sales schema, you're going to find a table called SalesTaxRate. It's all the way down here at the very bottom. I'm going to write a query that pulls out some information from this table. I'll select the TaxRate and Name columns from the table. When I execute the query, we'll see that we get 29 results, and I can see that number right down here in the bottom right-hand corner. And this represents all of the different tax rates that are stored in this data table. The first three rows that are returned correspond to Alberta, Ontario, and Quebec in Canada. In the SELECT statement up above I can return just those three records by adding TOP 3 after the keyword SELECT. Some people…

Contents