Description
The SQL keyword SELECT TOP is used to fetch a specific number of records.
- 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 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;