Learn From - Interactive SQL



SQL TOP Clause


TOP Clause can be used to retrieve the first few records from a table. Usually for tables with millions of records, this can be used to fetch few records faster. This enhances the performance of the SQL query.

Syntax for SQL Top


SELECT TOP number|percent column_name1, column_name2 ..
FROM table_name

The SQL Top Example


Below is shown the "Customers" table:

CustomerID CustomerName EmailID Address City PostalCode Country
C001 Fredrick Johnson FJohnson@yahoo.com Berkeley Gardens 12 Brewery London WX1 6LT UK
C002 Mary Davidson Mary@gmail.com 35 King George Madrid 28023 Spain
C003 George Clooney George@hotmail.com Obere Str. 57 Berlin 12209 Germany
C004 David Louis David@mail.com 2743 Bering St. NewJersy 07019 USA
C005 Johnny Anderson Johnny@gmail.com 55 Grizzly Peak Rd. NewJersy 07019 USA
C006 Paul Henriot PaulHenriot@yahoo.com 59 rue de l'Abbaye Paris 51100 France
C007 Henry King Henry@mail.com 120 Hanover Sq. London WA1 1DP UK
C008 Robert John Robert@gmail.com 87 Polk St. Suite 5 San Francisco 94117 USA

Text Editor below has the SQL Query, click the "View Result" button, to see the result.

Retrieve top 5 records from Customers table

Select Top 5 CustomerID, CustomerName, EmailID, Address, City, PostalCode, Country
from Customers;

SQL in Text Editor: