WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL SELECT TOP Clause


The SQL SELECT TOP Clause

The SELECT TOP clause is used to specify the number of records to return.

The SELECT TOP clause can be very useful on large tables with thousands of records. Returning a large number of records can impact on performance.

SQL Server / MS Access Syntax

SELECT TOP number|percent column_name(s)
FROM table_name;



SQL SELECT TOP Equivalent in MySQL and Oracle

MySQL Syntax

SELECT column_name(s)
FROM table_name
LIMIT number;

Example

SELECT *
FROM Persons
LIMIT 5;

Oracle Syntax

SELECT column_name(s)
FROM table_name
WHERE ROWNUM <= number;

Example

SELECT *
FROM Persons
WHERE ROWNUM <=5;

Database

In this tutorial we use the Northwind sample database.

Below is a selection from the "Customers" table:

CustomerID FirstName Phone Username Password Email address
1

Robert J. Drake (08) 8335 8518 Homeen1989 oeZie7dud RobertJDrake@teleworm.us
2 Yolanda J. Berry (03) 5344 0422 Ouroor Ieph4Xe2phee MoonLightdining.com.au
3 Laura J. Ridley (08) 8343 7035 Younbuthouse Sugeeha1o LauraJRidley@teleworm.us
4

Linda R. Doyle (02) 6778 4799 Ashery oo3ki3Thudo LindaRDoyle@armyspy.com
5 Priscilla A. Moore (08) 8205 4768 Lumbeavy39 iF0haeGoo PriscillaAMoore@teleworm.us



SQL SELECT TOP Example

The following SQL statement selects the three first records from the "Customers" table:

Example

SELECT TOP 3 * FROM Customers;