home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / database / oracle / 1451 < prev    next >
Encoding:
Internet Message Format  |  1992-09-01  |  1.4 KB

  1. Path: sparky!uunet!mcsun!uknet!keele!csa09
  2. From: csa09@seq1.keele.ac.uk (Paul Singleton)
  3. Newsgroups: comp.databases.oracle
  4. Subject: Re: SQL*plus -- limiting maximum number of returned rows?
  5. Message-ID: <3894@keele.keele.ac.uk>
  6. Date: 1 Sep 92 13:05:17 GMT
  7. References: <1992Aug31.223520.28312@massey.ac.nz>
  8. Organization: University of Keele, England
  9. Lines: 23
  10.  
  11. From article <1992Aug31.223520.28312@massey.ac.nz>, by M.W.Stern@massey.ac.nz (M.W. Stern):
  12.  
  13. > > I am working on a report that is supposed to find the "top 5" items in 
  14. > > a catagory.  The query returns 0 or more rows based on the selection
  15. > > criteria, sorted in the appropriate order.  Some queries return a dozen
  16. > > or more rows, but I'm only interested in the first 5.
  17.  
  18. > I believe the answer to this goes something like this,
  19. > SELECT value FROM table WHERE ROWNUM <= 5
  20.  
  21. But I think the poster wanted the first N rows of a result relation, not
  22. a base table?  This is one instance where the generalised SQL construct
  23.  
  24.     SELECT value FROM ( SELECT etc FROM etc WHERE etc )
  25.     WHERE ROWNUM <= 5
  26.  
  27. would be valuable, assuming that intermediate relations had ROWNUMs.
  28. ----
  29.   __   __    Paul Singleton (Mr)           JANET: paul@uk.ac.keele.cs
  30.  |__) (__    Computer Science Dept.        other: paul@cs.keele.ac.uk
  31.  |  .  __).  Keele University, Newcastle,    tel: +44 (0)782 621111 x7355
  32.              Staffs ST5 5BG, ENGLAND         fax: +44 (0)782 713082
  33.