Description
The SQL keyword TOP is used to specify the number of records to return in a SELECT statement result set.
- This keyword TOP is valid only in the SQL Server database system.
- MySQL uses the LIMIT keyword and Oracle uses the ROWNUM keyword for the same purpose.
SELECT With TOP
The below SQL returns the five records from the result set.
SELECT TOP 5 * FROM customers;
SELECT With LIMIT
The below SQL returns the five records from the result set.
SELECT * FROM customers
LIMIT 5;
SELECT With ROWNUM
The below SQL returns the five records from the result set.
SELECT * FROM customers
WHERE ROWNUM <= 5;