The TOP clause is used to return a specified number of rows from the SELECT result.    It becomes more meaningful when used in conjunction with ORDER BY.  As then you’re able to find rows with top values. 

For instance, here are the ten highest products by list price. 

SELECT TOP 10 Name, ListPrice From Production.Product Order By ListPrice DESC;
/* Answer */
SELECT TOP 10 Name, ListPrice 
From Production.Product 
Order By ListPrice DESC 

What makes this work is that we use the DESC keyword to sort ListPrice in descending (9 to 0) order.  If case you’re wondering, there is no BOTTOM keyword.  To simulate this, just use an ORDER BY in ASC (Ascending) order. 

TOP Clause as Percent 

You can also use TOP to find a percentage of row.   For instance, to select the top five percent of all products, in terms of ListPrice, in the products table, write the following SQL:

SELECT TOP 5 PERCENT Name, ListPrice FROM Production.Product ORDER BY ListPrice DESC;
/* Answer */
SELECT TOP 5 PERCENT Name, ListPrice 
FROM Production.Product 
ORDER BY ListPrice DESC

In summary you can use the TOP clause to return an absolute number of rows, or a percentage.  TOP gains more meaning used in conjunction with ORDER BY.  Here you’re able to select the TOP or “BOTTOM” values, depending on whether you sort your values in DESC (descending) or ASC (Ascending) order. 

Additional Resources 

To learn more about TOP, check out these useful resources: 

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Are YOU READY TO START LEARNING SQL SERVER, BUT DON'T KNOW WHERE TO START?

Nothing is worse than, being excited to learn a new tool but not knowing where to start, wasting time learning the wrong features, and being overwhelmed .

But it doesn't have to be this way.

I'm Putting together a free email course to help you get started learning SQL Server.

__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"b6728":{"name":"Main Accent","parent":-1},"03296":{"name":"Accent Low Opacity","parent":"b6728"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"b6728":{"val":"var(--tcb-skin-color-0)"},"03296":{"val":"rgba(17, 72, 95, 0.5)","hsl_parent_dependency":{"h":198,"l":0.22,"s":0.7}}},"gradients":[]},"original":{"colors":{"b6728":{"val":"rgb(47, 138, 229)","hsl":{"h":210,"s":0.77,"l":0.54,"a":1}},"03296":{"val":"rgba(47, 138, 229, 0.5)","hsl_parent_dependency":{"h":210,"s":0.77,"l":0.54,"a":0.5}}},"gradients":[]}}]}__CONFIG_colors_palette__
Name*
Email*
__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"dffbe":{"name":"Main Accent","parent":-1}},"gradients":[]},"palettes":[{"name":"Default Palette","value":{"colors":{"dffbe":{"val":"var(--tcb-color-4)"}},"gradients":[]},"original":{"colors":{"dffbe":{"val":"rgb(19, 114, 211)","hsl":{"h":210,"s":0.83,"l":0.45}}},"gradients":[]}}]}__CONFIG_colors_palette__
Sign Up
>