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

  1. Path: sparky!uunet!stanford.edu!unixhub!tethys.SLAC.Stanford.EDU!ian
  2. From: ian@tethys.SLAC.Stanford.EDU (Ian A. MacGregor)
  3. Newsgroups: comp.databases.oracle
  4. Subject: Re: SQL*plus -- limiting maximum number of returned rows?
  5. Message-ID: <5398@unixhub.SLAC.Stanford.EDU>
  6. Date: 1 Sep 92 14:56:53 GMT
  7. References: <BtuK40.8By@ef2007.efhd.ford.com>
  8. Sender: news@unixhub.SLAC.Stanford.EDU
  9. Lines: 41
  10. Nntp-Posting-Host: tethys.slac.stanford.edu
  11.  
  12. In article <BtuK40.8By@ef2007.efhd.ford.com>, wwm@ef2007.efhd.ford.com (William Meahan) writes:
  13. |> In SQL*Plus (not embedded SQL!) is there any way of limiting the number
  14. |> of rows returned by a query?
  15. |> 
  16. |> I am working on a report that is supposed to find the "top 5" items in 
  17. |> a catagory.  The query returns 0 or more rows based on the selection
  18. |> criteria, sorted in the appropriate order.  Some queries return a dozen
  19. |> or more rows, but I'm only interested in the first 5.
  20. |> 
  21. |> If I were using embedded SQL in a C program (or a perl script using 
  22. |> oraperl) the solution would be trivial.  For internal reasons, however,
  23. |> I'm stuck with using SQL*Plus.
  24. |> 
  25. |> Any ideas?
  26. |> 
  27. |> 
  28. |> --
  29. |> Bill Meahan
  30. |> -- 
  31. |> Bill Meahan            |EFHD Information Systems Staff
  32. |> Technical Consultant        |Ford Motor Company
  33. |> wwm@ef2007.efhd.ford.com          | +1 313 487 6122
  34. |> ...!fmsrl7!ef2007!wwm           |I'm not paid to speak for Ford!
  35.  
  36. The top 5 articles in a category may return more than 5 rows.  The following
  37. query selects the people with the 5 highest salaried people from the Oracle 
  38. EMP table.
  39.  
  40.      select * from emp  a where 5 >
  41.      (select count(sal) from emp b where
  42.      b.sal > a.sal)
  43.      order by sal desc
  44. /
  45.  
  46. If there are ties for the fifth highest paid person all rows containing the
  47. "tie" value will be retrieved.
  48.  
  49.                          Ian MacGregor
  50.                          Stanford Linear Accelerator Center
  51.                          IAN@SLAC.STANFORD.EDU
  52.                          (415) 926-3528  
  53.