*Rownum and Order by*

From: <ram%artecon_at_hp-sdd.sdd.hp.com>
Date: 10 Jun 1992 15:01:40 -0500
Message-ID: <9206101820.AA11994_at_artecon>


Hello World

	I have a problem in using "rownum" and "order by" in the same
	query. Consider a table with columns PART_NO and UNITS_SOLD
	with about 12000 records. Someone wants to see the top 20 parts.
	So i go

		select part_no, units_sold
		from   bigtable
		where  rownum < 21
		order  by units_sold desc

	Of course, it gives me 20 lines of fine garbage. I checked the
	manual and i more or less found out that i can't use these two
	in the same query. Is there any other way to do this ? Ofcourse
	I can redirect the query (without rownum condition) into a file
	and print the top <whatever> lines to a printer. 

	If there is any other way, I would appreciate if someone could 
	tell me about it!


						*Ramesh*
				     ram%artecon_at_hp-sdd.sdd.hp.com

ps
	It is at times like this when i turn to my favorite - "rpt"
	Just declare recordcnt 99 ; if recordcnt > 20 stop 
		;)
Received on Wed Jun 10 1992 - 22:01:40 CEST

Original text of this message