Thread: Order by

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    7
    Rep Power
    0

    Order by


    Hi,I have a little problem and i dont know how to solve it.

    I have a query that returns a list of names that are always the same ones,for example:

    'Literature'
    'Mathematics'
    'Science'
    'Chemistry'
    ...

    My problem is that i want to order this result just like i wrote it,so i can't use order by that column. Anyone know a way to that?

    Thanks!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    68
    Rep Power
    11
    Please have a look at the rownum function as in:

    select rownum, owner, table_name from all_tables

    Cheers,
    Dan
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    68
    Rep Power
    11
    You might be better off by looking at the address of each row.
    Please try:

    1) select rowid from your_table;

    2) select rowidtochar(rowid) from your_table;

    3) select rowidtochar(rowid) from your_table order by rowidtochar(rowid);

    Cheers,
    Dan
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2003
    Location
    Paris Uppland
    Posts
    2,382
    Rep Power
    391
    Code:
    order by 
    case subject
    when 'Literature' then 1
    when 'Mathematics' then 2
    when 'Science' then 3
    when 'Chemistry' then 4 end
    If you have a version that does not support case expressions, you can use the decode function.

IMN logo majestic logo threadwatch logo seochat tools logo