SQL TOP Statement

The SQL TOP statement is used with the TOP clause to select the specific number of records to return in the query result. This is usually done when the result of the query is too large and specific number of records needed to be output. This ofcourse helps to reduce the load on the server and thus helps with the server performance.

  • The TOP clause is used to specify the number of records to return
  • The TOP clause helps to filter huge query results to keep performance
  • The TOP clause is not supported by all database systems
  • There are two different ways to call the SQL TOP statement; either by number or percent

SQL TOP statement by number

SELECT TOP number column_name(s)

FROM table_name

SQL TOP statement by percent

SELECT TOP percent column_name(s)

FROM table_name


Database Table “Members”

Id FirstName LastName Email City Phone
1 Gilbert Duncan [email protected] Newark 973-600-3300
2 Elvis Daniels [email protected] Piscataway 862-600-3050
3 Michael Green [email protected] Detroit 732-500-5050
4 Kelvin Graham [email protected] Detroit 732-555-5050
5 Arthur Owen [email protected] Toronto 416-300-0685

SQL TOP Example

SELECT TOP 3 *

FROM Members

RESULT of SQL TOP statement above will be

Id FirstName LastName Email City Phone
1 Gilbert Duncan [email protected] Newark 973-600-3300
2 Elvis Daniels [email protected] Piscataway 862-600-3050
3 Michael Green [email protected] Detroit 732-500-5050

The result above shows the top 3 records of the table “Members”

Now using the SQL TOP by percent

SELECT TOP 40 PERCENT *

FROM Members

RESULT of SQL TOP statement above will be

Id FirstName LastName Email City Phone
1 Gilbert Duncan [email protected] Newark 973-600-3300
2 Elvis Daniels [email protected] Piscataway 862-600-3050

The result above shows the 40 percent of the records in table “Members”