WinSQL » Knowledge base

Document information

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)

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.

User comments

Posted by Yvone on 3/24/10 10:24 AM

select * from T_REF_LIST where rownum <=5 I got error message Error: ERROR: Attribute 'ROWNUM' not found (State:42S22, Native Code: 1F)

Posted by Meg on 10/25/10 5:12 PM

Getting Error" Error: ERROR: Attribute 'ROWNUM' not found (State:42S22, Native Code: 1F)

Add a comment to this document

Do you have a helpful tip related to this document that you'd like to share with other users?

Important: This area is reserved for useful tips. Therefore, do not post any questions here. Instead, use our public forums to post questions.


Social Media

Powered by