SQL ROWNUM Keyword
The ROWNUM keyword is used in Oracle databases to limit the number of rows returned by a query. It allows you to filter and return a specific number of rows from a result set.
Note:
- SQL Server uses
SELECT TOP
- MySQL and SQLite use
LIMIT
- Oracle uses
ROWNUM
SQL ROWNUM Syntax
SQL
x
1
SELECT column_names
2
FROM table_name
3
WHERE ROWNUM <= number;
SQL ROWNUM Example
This query selects the first 3 rows from the Patients
table.
SQL
1
1
SELECT *
2
FROM Patients
3
WHERE ROWNUM <= 3;
Note: This code does not work in the TechKubo playground. SQLite (and TechKubo) does not support
ROWNUM
. To achieve the same result in SQLite, useLIMIT
instead.
SQL LIMIT Equivalent Example
SQL
1
1
SELECT *
2
FROM Patients
3
LIMIT 3;
