From the course: Querying Microsoft SQL Server 2012

Unlock the full course today

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

Using the TOP option

Using the TOP option - SQL Server Tutorial

From the course: Querying Microsoft SQL Server 2012

Start my 1-month free trial

Using the TOP option

So far we've taken a look at using the ORDER BY and the GROUP BY clauses to affect the results sets that we get from our queries. Sometimes though, you might just want a small representative sample of the records from the table, and you don't actually need to return all of the rows. So what we'll take a look at is another facility in SQL Server known as TOP. TOP allows you to specify a number of rows or a percentage of rows that you want to return. Let's see what that looks like in SQL Server. To give you an example, our first query that we'll execute is just a standard SELECT * from Person.Address. And we're just going to do this, so you can see the row count that actually exists in that table. And then, we'll use that for comparisons when we start looking at the top keyword for a specific number or to specify a number of rows. So we executed a query against that person table, and we see that, and we actually have 19,614 rows. Again, it's just from the person address table, we've…

Contents