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