Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Top-N records.

RE: Top-N records.

From: Sachin Puri <sachin_at_siworldwide.com>
Date: Mon, 15 Jan 2001 12:19:17 +0530
Message-Id: <10741.126637@fatcity.com>


well ALDI if you are using Oracle 8i then i have one more simpler query for you to fetch top 20 records.

SELECT salary FROM (SELECT salary FROM EMPlOYEE ORDER BY salary DESC) WHERE ROWNUM < 21;

-----Original Message-----
From: Sachin Puri [mailto:sachin_at_siworldwide.com] Sent: Monday, January 15, 2001 9:30 AM
To: Multiple recipients of list ORACLE-L Subject: RE: Top-N records.

Aldi
I just saw this topic today. I also saw comments of various dbas regarding your query but was
not impressed by anyone.
You can successfully use this query and i bet this will not give you any problems:

select salary from employee x where 20 > (select count(*) from employee y where y.salary > x.salary) order by x.salary desc;

However if the u want to have top 20 distinct salaries then add distinct clause.

Sachin Puri
Oracle Development and Administration
Solutions Infosystems

-----Original Message-----
Sent: Saturday, January 13, 2001 2:54 AM To: Multiple recipients of list ORACLE-L

Hi List,

This question has been discussed so many times. But I dont have the trick now.
Could you please send me the trick to select top-20 salary of scott.employee table ?
Thanks.

Aldi



Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

--

Please see the official ORACLE-L FAQ: http://www.orafaq.com
--

Author: Aldi Barco
  INET: ipal_at_hotmail.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).

--

Please see the official ORACLE-L FAQ: http://www.orafaq.com
--

Author: Sachin Puri
  INET: sachin_at_siworldwide.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may Received on Mon Jan 15 2001 - 00:49:17 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US