how to fetch top 20 rows

greenspun.com : LUSENET : DBAzine : One Thread

Dear Sir/Madame, We are developing an application where a user wants to see the top 20 customer. I am having a table with customer_name, and balances. We want to see the top 20 customers. If i am writing query like this, then this is not fetching the correct records. How to get the top 20 records.

For example, I have the following:

select cust_name, balance from cust where rownum < 21 order by balance desc;

As we know that it assigned rownum based on the selection and then apply order by clause.

Waiting for quicker reply

Rajesh Jain

-- RK Jain (joharirajesh@rediffmail.com), August 10, 2002

Answers

please see the link below http://www.db2mag.com/db_area/archives/2001/q3/programmers.shtml

-- basivi reddy inaganti (inaganb@nationwide.com), August 27, 2002.

Moderation questions? read the FAQ