Home » SQL & PL/SQL » SQL & PL/SQL » Returning only the first12 records returned by a query (Oracle 8i)
Returning only the first12 records returned by a query [message #303024] Wed, 27 February 2008 11:29 Go to next message
matpj
Messages: 115
Registered: March 2006
Location: London, UK
Senior Member

I all,
I have the following query which returns a number of rows.

SELECT AWDCallData.MonthYear
, AWDCallData.Tickets_Opened
, AWDCallData.Tickets_Closed
, AWDCallData.Difference
, AWDCallData.Currently_Active
, AWDCallData.Currently_Open
, AWDCallData.Suspended_Awaiting_Client
, AWDCallData.Suspended_DST
, AWDCallData.Suspended_UK_Support
, AWDCallData.Total_UK_Suspended
, AWDCallData.Suspended_Development
, AWDCallData.Ticket_Resolved
FROM AWDMRDB.dbo.AWDCallData AWDCallData
ORDER BY AWDCallData.MonthYear


I want to be able to force it to only return the first 12 rows of data.
Is this possible?

[Updated on: Wed, 27 February 2008 11:53] by Moderator

Report message to a moderator

Re: Returning only the first12 records returned by a query [message #303025 is a reply to message #303024] Wed, 27 February 2008 11:32 Go to previous messageGo to next message
ThomasG
Messages: 3189
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
There is a pseudo-column "rownum" which you can use in the where-clause, like

where rownum < 13




Re: Returning only the first12 records returned by a query [message #303029 is a reply to message #303025] Wed, 27 February 2008 11:54 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
ThomasG wrote on Wed, 27 February 2008 18:32
There is a pseudo-column "rownum" which you can use in the where-clause, like

where rownum < 13






That only works if you do an "order by" FIRST. So, you cannot have the restriction on rownum at the same level in your query as the order by!
Re: Returning only the first12 records returned by a query [message #303032 is a reply to message #303029] Wed, 27 February 2008 12:07 Go to previous message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
Quote:
That only works if you do an "order by" FIRST. So, you cannot have the restriction on rownum at the same level in your query as the order by!
Provided that the OP doesn't want an arbitrary 12 rows (Which I must admit, is what the topic title makes it sound like)
Previous Topic: String too long (Concatenation)
Next Topic: REGEXP_LIKE - using field name as part of regular expression?
Goto Forum:
  


Current Time: Mon Dec 05 08:50:12 CST 2016

Total time taken to generate the page: 0.05728 seconds