Oracle Sql Select Top ROWNUM
Limiting result rows we use sql select ROWNUM statement for Oracle Database instead of TOP.
In this sql select ROWNUM (similiar to TOP) tutorial we will use the sample table below for our sql select ROWNUM statement examples.
We will limit the result rows (records) in the users table with ROWNUM.
Users Table; tbl_users
| id | Name | Password | Age | |
|---|---|---|---|---|
| 1 | John Doe | johndoe@j.com | e56Hdf-2 | 34 |
| 2 | Jane Doe | janedoe@j.com | p59Hdf-2 | 32 |
| 2 | Gary Doe | garydoe@j.com | y02Tdf-2 | 23 |
SQL Select ROWNUM (Top) Code
SELECT * from tbl_users WHERE ROWNUM <= 2
This sql query will return top 2 rows records from users table.
Query Result| id | Name | Password | Age | |
|---|---|---|---|---|
| 1 | John Doe | johndoe@j.com | e56Hdf-2 | 34 |
| 2 | Jane Doe | janedoe@j.com | p59Hdf-2 | 32 |
Note that you can order results by using ORDER in your sql ROWNUM (similiar to top) queries.