home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.databases.oracle
- Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!destroyer!fmsrl7!ef2007!wwm
- From: wwm@ef2007.efhd.ford.com (William Meahan)
- Subject: Re: SQL*plus -- limiting maximum number of returned rows?
- Message-ID: <BtvEIC.Eo0@ef2007.efhd.ford.com>
- Organization: EFHD Ford Motor Company
- X-Newsreader: Tin 1.1 PL3
- References: <1992Aug31.204947.7478@news.iastate.edu>
- Distribution: usa
- Date: Mon, 31 Aug 1992 22:58:59 GMT
- Lines: 60
-
- GO.MSB@isumvs.iastate.edu writes:
- : In article <BtuK40.8By@ef2007.efhd.ford.com>,
- : wwm@ef2007.efhd.ford.com (William Meahan) writes:
- : >In SQL*Plus (not embedded SQL!) is there any way of limiting the number
- : >of rows returned by a query?
- : >
- : >I am working on a report that is supposed to find the "top 5" items in
- : >a catagory. The query returns 0 or more rows based on the selection
- : >criteria, sorted in the appropriate order. Some queries return a dozen
- : >or more rows, but I'm only interested in the first 5.
- : >
- : >If I were using embedded SQL in a C program (or a perl script using
- : >oraperl) the solution would be trivial. For internal reasons, however,
- : >I'm stuck with using SQL*Plus.
- : >
- : >Any ideas?
- : >--
- : >Bill Meahan |EFHD Information Systems Staff
- : >Technical Consultant |Ford Motor Company
- : >wwm@ef2007.efhd.ford.com | +1 313 487 6122
- : >...!fmsrl7!ef2007!wwm |I'm not paid to speak for Ford!
- : ---------------------------------
- : try WHERE ROWNUM < 6
- :
- : ALthough this works, I hate it. If the query returns 2000 rows, it still
- : does and you wait for it to do so. It then hands you the first 5 or whatever
- : you request. ROWNUM is a pseudo-column and doesn't exist until some rows are
- : returned.
- :
- : Marvin Beck Iowa State University
-
- Yep. That'll do exactly what I _ASKED_ for, but not what I want :-(
- (don't you just hate it when your brain goes on vacation while you're
- entering a question into NetNews?)
-
- The reality is more complex.
-
- Consider the following records:
-
-
- Machine Station Fault Count
- -------- -------- ------- -----
- Machine1 Station1 Code22 32
- Machine1 Station1 Code36 16
- Machine2 Station1 Code06 427
- Machine1 Station2 Code13 202
- ...
- etc.
-
-
- The select will return many rows with combinations of Machine, Station and
- Fault. The trick is to select the "Top 5" Faults for EACH combination
- of Machine and Station based on the value of Count.
-
- Much trickier, eh?
- --
- Bill Meahan |EFHD Information Systems Staff
- Technical Consultant |Ford Motor Company
- wwm@ef2007.efhd.ford.com | +1 313 487 6122
- ...!fmsrl7!ef2007!wwm |I'm not paid to speak for Ford!
- QUIT
-
- ....!fmsrl7!ef2007!wwm |I'm not paid to speak for Ford!
-