Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: where rownum =1 NOT producing expected TOP 1results with order by

Re: where rownum =1 NOT producing expected TOP 1results with order by

From: Charles Hooper <hooperc2000_at_yahoo.com>
Date: 7 Feb 2007 12:27:02 -0800
Message-ID: <1170880022.138922.257860@m58g2000cwm.googlegroups.com>


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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US