Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: where rownum =1 NOT producing expected TOP 1results with order by
On Feb 7, 2:56 pm, "jobs" <j..._at_webdos.com> wrote:
> This query does not give me the correct row. Am I missing something
> here? I'm looking for the first row when sorting by that logdate..
> thanks.
>
> select logtype into g from CPM_ERRORLOG where cpmjobno=29 and
> rownum=1 order by logdate desc;
>
> Thanks.
That is expected. ROWNUM is evaluated before the ORDER BY - I made the same logical mistake a couple times too.
See:
http://www.oracle.com/technology/oramag/oracle/07-jan/o17asktom.html
Charles Hooper
PC Support Specialist
K&M Machine-Fabricating, Inc.
Received on Wed Feb 07 2007 - 14:27:02 CST