home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / database / oracle / 2734 < prev    next >
Encoding:
Text File  |  1993-01-08  |  1.8 KB  |  53 lines

  1. Newsgroups: comp.databases.oracle
  2. Path: sparky!uunet!mcsun!chsun!osnbe!
  3. From: rheiger@renext.eiger.olivetti.ch (Richard H. E. Eiger)
  4. Subject: Re: 40 values in desc order
  5. Message-ID: <1993Jan8.200238.534@osnbe.Olivetti.ch>
  6. Sender: @osnbe.Olivetti.ch
  7. Nntp-Posting-Host: renext
  8. Reply-To: rheiger@renext.eiger.olivetti.ch
  9. Organization: Olivetti (Schweiz) AG, Branch Office Berne
  10. References: <6622.2b485a61@hayes.com>
  11. Date: Fri, 8 Jan 1993 20:02:38 GMT
  12. Lines: 39
  13.  
  14. In article <6622.2b485a61@hayes.com> fgreene@hayes.com writes:
  15. > In article <Bzo2t0.67@lut.fi>, hietanen@lut.fi (Pentti Hietanen) writes:
  16. > > 
  17. > > What kind of sql sentence should we use to get 40 values
  18. > > from database in descending order?
  19. > > 
  20. > > Pentti Hietanen, student of Lappeenranta University of Technology, Finland.
  21. > > internet: hietanen%lut.fi
  22. > Probably the easiest way is to use the ROWNUM function.  For example,
  23. >     SELECT field1, field2, fieldn
  24. >     FROM   the_table
  25. >     WHERE  ROWNUM < 40;
  26. This will only limit the output to the first 40 rows. It will not order them in  
  27. a predictible manner. If you want to order the rows descending you should  
  28. probably use the "ORDER BY attr1, attr2... DESCENDING" clause. However this  
  29. will not restrict the select to 40 rows. To do both you could
  30.  
  31. select <attribute1>,....
  32. from tablename
  33. where key_attr_list in (
  34. select key_attr_list
  35. from tablename
  36. order by order_attr_list descending)
  37. where rownum < 40;
  38.  
  39. This is probably rather SLOW. I am sure some SQL cracks will have a better  
  40. solution.
  41.  
  42. --
  43.                          
  44.     ___           _____2
  45.    /   )  /  /   /        Richard H. E. Eiger
  46.   /_ _/  /__/   /__       Ing. Informatik HTL
  47.  /\     /  /   /          Unregistered NeXT fan
  48. /  \   /  /   /_____      rheiger@renext.eiger.olivetti.ch (NeXT mail welcome)
  49.