Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003
    Posts
    2

    Unanswered: Lists of numbers

    I have a list of not ordered numbers that i need to use but i dont want to order them i want to use them in reverse order to what they are. Ie i wish to use the last one first and the first one last etc. But i was wondering how i would implement changing these records around so i can do this.

    Ie

    1,2,12,4,5 - origenal
    5,4,12,2,1 - What i want it like

    Hope you can help

    Andy

  2. #2
    Join Date
    Mar 2002
    Location
    Reading, UK
    Posts
    1,137
    Dont know if this is what you are after...

    select * from
    (select rownum id, a.* from table a) x
    order by id desc

    NOTE however the order of the rows in the inner select is undefined so something which might cause a different execution plan to be used i.e. adding some new index might cause the order to be changed.

    Alan

  3. #3
    Join Date
    Apr 2003
    Location
    Greenville, SC (USA)
    Posts
    1,155
    If the order of the rows is true ... You can use rowid in the order by clause
    ...


    select .... from ... order by rowid asc ... (should give you the original)
    select .... from ... order by rowid desc .. (should give you what you want)

    HTH
    Gregg

  4. #4
    Join Date
    Dec 2003
    Location
    INDIA
    Posts
    3

    Re: Lists of numbers

    U can try like this this will solve u r problem

    select rownum r,empno from emp;

    R EMPNO
    ------ ----------
    1 7369
    2 7499
    3 7521
    4 7566
    5 7654
    6 7698
    7 7782
    8 7788
    9 7839
    10 7844
    11 7876

    R EMPNO
    ------ ----------
    12 7900
    13 7902
    14 7934

    the above said one is the defalut

    below one is the set u need

    select r, empno from(
    select rownum r,empno from emp)
    order by r desc;

    R EMPNO
    ----- ----------
    14 7934
    13 7902
    12 7900
    11 7876
    10 7844
    9 7839
    8 7788
    7 7782
    6 7698
    5 7654
    4 7566

    R EMPNO
    ----- ----------
    3 7521
    2 7499
    1 7369

Posting Permissions

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