Re: How to get the first four rows???

From: Muhammad A. Malik <mamalik_at_cs.wmich.edu>
Date: 1996/05/17
Message-ID: <319C877B.564C_at_cs.wmich.edu>#1/1


Ramesh Garapaty wrote:
>
> Hi!
> I have a SQL as follows:
> SELECT x_date
> FROM y_table
> ORDER BY x_date desc
>
> However I want the first four rows only. If I say WHERE rownum < 5 it
> returns the rows even before sorting by descending order. All I want to
> see is the latest four dates from the database. Is there a SQL with
> which we can do this???
>
> Thanks
>
> Ramesh

SELECT x_date
FROM y_table a

WHERE 	4 >	(SELECT count(*) 
		 FROM y_table
		 WHERE x_date < a.x_date)		

ORDER BY x_date desc

Some readjusment in '<' or '>' sign in the above query will definitly solve your problem.

-- 

Muhammad A. Malik
mamalik_at_cs.wmich.edu
+1 (616) 342-4569
Received on Fri May 17 1996 - 00:00:00 CEST

Original text of this message