Re: problem with ROWNUM

From: TurkBear <noone_at_nowhere.com>
Date: Wed, 18 Apr 2001 11:44:05 -0500
Message-ID: <2qgrdtc84ji41c8bm346m2gd9qipfac90d_at_4ax.com>


You need to do a subquery for the sorting then use the rownum :

select blah,blah,blah from
 (select blah,blah,blah from sametablenames where <complicated predicate> order by attribute desc )
where rownum <= :maxRows;

hth

belingueres_at_lycos.com ("Gabriel Belingueres") wrote:

>OK. I got more questions! :)
>
>I have a very complicated query that have this format:
>
>select blah blah
>from blah, blah, blah
>where
> (a complicated predicate here) AND (ROWNUM <= :maxRows)
>order by attribute DESC;
>
>The thing is that SQL stops when it reaches the maxRows rows, and THEN it sorts the rows. I got this problem since I need to return the rows ordered by date in descending order, but the query doesn't return the LAST date in the tables, because of the problem with ROWNUM.
>
>What I need to do is get all the rows sorted, and THEN select the first maxRows.
>
>How do I do that?
>
>Regards,
>Gabriel
>
>
>
>Get 250 color business cards for FREE!
>http://businesscards.lycos.com/vp/fastpath/

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 80,000 Newsgroups - 16 Different Servers! =----- Received on Wed Apr 18 2001 - 18:44:05 CEST

Original text of this message