From Alex.Hillman@usmint.treas.gov Fri, 04 May 2001 13:58:47 -0700 From: "Hillman, Alex" Date: Fri, 04 May 2001 13:58:47 -0700 Subject: RE: How can I cut off a query after 3 lines? Message-ID: MIME-Version: 1.0 Content-Type: text/plain Title: RE: How can I cut off a query after 3 lines? Keep in mind also that now Oracle has analitical functions like rank etc. which can be used to resolve such problems and SQL is much simpler.   Alex Hillman -----Original Message-----From: Jacques Kilchoer [mailto:Jacques.Kilchoer@quest.com]Sent: Friday, May 04, 2001 3:35 PMTo: Multiple recipients of list ORACLE-LSubject: RE: How can I cut off a query after 3 lines? > -----Original Message----- > From: MKirk [mailto:mkirk@hot.ee] > > Q: how can you specify with a select statement how many rows > are given as a > result? I would only like to get the first three lines..... > > here is what I have.... > > > 1  SELECT machine_name, login, Count(login) AS CountOfLogin FROM > login_history >   2  group by machine_name, login >   3* order by count(login) desc >   4  ; > ... Please note that the "rownum < 4" clausee will be applied BEFORE a group by or order by. At the end of each message sent to the list is a link to ORAFAQ. Click on the link, and go visit the SQL section. You will see there answers to the following questions: Can one retrieve only the Nth row from a table? http://www.orafaq.com/faqsql.htm#NTHROW Can one retrieve only rows X to Y from a table? http://www.orafaq.com/faqsql.htm#ROWXtoY How does one select EVERY Nth row from a table? http://www.orafaq.com/faqsql.htm#EVERYNTHROW How does one select the TOP N rows from a table? http://www.orafaq.com/faqsql.htm#TOP ------ Jacques R. Kilchoer (949) 754-8816 Quest Software, Inc. 8001 Irvine Center Drive Irvine, California 92618 U.S.A. http://www.quest.com