home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.databases.oracle
- Path: sparky!uunet!mcsun!chsun!osnbe!
- From: rheiger@renext.eiger.olivetti.ch (Richard H. E. Eiger)
- Subject: Re: 40 values in desc order
- Message-ID: <1993Jan8.200238.534@osnbe.Olivetti.ch>
- Sender: @osnbe.Olivetti.ch
- Nntp-Posting-Host: renext
- Reply-To: rheiger@renext.eiger.olivetti.ch
- Organization: Olivetti (Schweiz) AG, Branch Office Berne
- References: <6622.2b485a61@hayes.com>
- Date: Fri, 8 Jan 1993 20:02:38 GMT
- Lines: 39
-
- 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;
- >
- This will only limit the output to the first 40 rows. It will not order them in
- a predictible manner. If you want to order the rows descending you should
- probably use the "ORDER BY attr1, attr2... DESCENDING" clause. However this
- will not restrict the select to 40 rows. To do both you could
-
- select <attribute1>,....
- from tablename
- where key_attr_list in (
- select key_attr_list
- from tablename
- order by order_attr_list descending)
- where rownum < 40;
-
- This is probably rather SLOW. I am sure some SQL cracks will have a better
- solution.
-
- --
-
- ___ _____2
- / ) / / / Richard H. E. Eiger
- /_ _/ /__/ /__ Ing. Informatik HTL
- /\ / / / Unregistered NeXT fan
- / \ / / /_____ rheiger@renext.eiger.olivetti.ch (NeXT mail welcome)
-