Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2005

    Question Unanswered: select Top 1 * from ... = rownum = 1?

    When I perform this, I get no data.
    My goal is to select top 1 record... do somethings with it.. then delete it and select the next record.

    select ID, NUMBER, NAME
    into v_id, v_no, v_name
    from SOURCE
    where rownum = 1;
    Thank you for your help

  2. #2
    Join Date
    Jan 2005
    Green Bay
    top 1 is almost equivilant to rownum =1

    Don't assume that

    select * from table where rownum = 1
    order by field1

    will be the lowest value in field 1.

    Sorry typo Will not be the lowest value in field 1

    where as top 1 performs the sort then gets top 1
    Last edited by rbackmann; 06-09-06 at 10:39.

  3. #3
    Join Date
    Jun 2004
    Liverpool, NY USA
    Not correct. The query

    select * from table where rownum = 1
    order by field1;

    will return the first random row it finds, however the query

     select * from
     (select * from table
       order by field1 asc)
     where rownum = 1;
    Will return the first sorted row. The where clause is used before the order clause.
    Last edited by beilstwh; 06-09-06 at 10:19.
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts