home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!oracle!unrepliable!bounce
- Newsgroups: comp.databases.oracle
- From: mfriedma@uucp (Michael Friedman)
- Subject: Re: 40 values in desc order
- Message-ID: <1993Jan5.200712.12169@oracle.us.oracle.com>
- Sender: usenet@oracle.us.oracle.com (Oracle News Poster)
- Nntp-Posting-Host: appseq
- Organization: Oracle Corporation
- References: <Bzo2t0.67@lut.fi> <6622.2b485a61@hayes.com>
- Date: Tue, 5 Jan 1993 20:07:12 GMT
- X-Disclaimer: This message was written by an unauthenticated user
- at Oracle Corporation. The opinions expressed are those
- of the user and not necessarily those of Oracle.
- Lines: 33
-
- In article <6622.2b485a61@hayes.com> fgreene@hayes.com writes:
- >In article <Bzo2t0.67@lut.fi>, hietanen@lut.fi (Pentti Hietanen) writes:
-
- >> What kind of sql sentence should we use to get 40 values
- >> from database in descending order?
-
- >> Pentti Hietanen, student of Lappeenranta University of Technology, Finland.
- >> internet: hietanen%lut.fi
-
- >Probably the easiest way is to use the ROWNUM function. For example,
-
- > SELECT field1, field2, fieldn
- > FROM the_table
- > WHERE ROWNUM < 40;
-
- First off, you need to do an order by.
-
- Secondly, unless you are satisfied with any 40 this will not work
- because rownum is assigned before the order_by.
-
- If you want the top 40 then try
-
- Select fields
- From the_table t1
- Where 40 >= (select count(*) from the_table t2 where
- t2.order_field > t1.order_field)
- Order by order_field DESC
-
- Good Luck
-
- --
- -------------------------------------------------------------------------------
- I am not an official Oracle spokesman. I speak for myself and no one else.
-