T-SQL Tutorials - TSQLTutorials.com

TOP Option


Introduction

The TOP option is used for limiting the output of a query result set. The TOP SQL Statement is often used with the SELECT statement. TOP can either specify the number of rows to return, or the precentage of rows to return. The ORDER BY clause can be used successfully with the TOP option. In other words, the ORDER BY will be completed before the rows are limited.

Using TOP with SELECT Statements

Syntax for returning n number of rows:

SELECT TOP n *
FROM table

Example for returning 10 rows:

SELECT TOP 10 *
FROM employees

Syntax for returning n percentage of rows:

SELECT TOP n PERCENT *
FROM table

Example for returning 20 percent of rows:

SELECT TOP 20 PERCENT *
FROM employees


Using TOP with SELECT Statements using ORDER BY clause

Example for returning top 10 highest paid employees:

SELECT TOP 10 *
FROM employees
ORDER BY Salary DESC


SQL Server 2014 Standard w/ 10CAL Edition, Media & License | 32 bit & 64 bit

Price: $299.99
Buy It Now
Brand New - Microsoft SQL Server 2012 Standard Edition SP3 and 10 CAL License

Price: $400
Buy It Now
SQL Server 2014 Standard Edition, 16 Core Processor License | unlimited USER CAL

Price: $599.99
Buy It Now
MSFT SQL Server 2008 R2 Standard Edition 32/x64 | 25CAL, Media, License

Price: $299.99
Buy It Now
MSFT SQL Server 2012 Standard Edition, 32bit & 64bit, Media & License w/10CAL

Price: $399.99
Buy It Now
Lenovo Microsoft SQL Server 2016 CAL (1 User)

Price: $199.99
Buy It Now







Copyright 2017 - TSQLTutorials.com