Revolving around the core of technology
Document ID: | 769 |
---|---|
Subject: | Retrieving the Top-N or Bottom-N Rows from a SQL Table |
Creation date: | 7/29/09 2:59 PM |
Last modified on: | 12/12/18 10:40 AM |
The following example shows how to retrieve top-N or bottom-N rows from an Oracle table. This example makes use of a pseudo-column in Oracle called ROWNUM and we want to retrieve top 5 rows.
select *
from (select * from CUSTOMER order by ID)
WHERE ROWNUM <= 5
Note: this example makes use of a feature called an "inline view" that is supported by Oracle but may not be supported in other RDBMS.
Posted by Yvone on 3/24/10 10:24 AM
Posted by Meg on 10/25/10 5:12 PM
Do you have a helpful tip related to this document that you'd like to share with other users?