SQL TOP

TOP is used to specify the number of rows to display in the result.

This SQL TOP clause is useful in tables with many records, to limit the number of rows to display in the query, and so the query faster, consuming less resources also in the system.

This clause is specified differently depending on the database system used.

SQL TOP clause for SQL SERVER

SELECT TOP number columnName PERCENT FROM tablename

SQL TOP clause for MySQL

SELECT column (s) FROM table LIMIT num

ORACLE SQL TOP clause for

SELECT column (s) FROM table WHERE ROWNUM <= num

TOP SQL Example for MySQL:

Given the following table 'people'

namesurnamenickname
HARRYCLARKWHITE
HARRYSMITHJOHNSON
JOHNBROWNANDERSON

I get the first 2 rows.

SELECT * FROM people LIMIT 2

Obtain the following result:

namesurnamenickname
HARRYCLARKWHITE
HARRYSMITHJOHNSON