Results 1 to 3 of 3

Thread: sort question

  1. #1
    Join Date
    May 2004
    Location
    New York
    Posts
    248

    Unanswered: sort question

    Was wondering if anybody had any work around

    imagine having a table with col1 and col2
    values are 1|A
    2|B
    3|C

    I want to be able to do a select and sort by B,A,C obviously asc or desc will not work.
    Do not want to make a bunch of select where col1=B then col1=A col1=C
    and fetch three different cursors

    Changing the data in the table is not an option either

    Any feedback would be greatly appreciated

    Cheers

  2. #2
    Join Date
    Nov 2004
    Posts
    143
    Hi,

    Try using the decode function fot the column B (decode value B as X, value A as Y and value C as Z) and then order by the column.
    Ex:
    --create table nitin (nm integer, name char(1));
    insert into nitin values (1, "A");
    insert into nitin values (2, "A");
    insert into nitin values (3, "A");
    insert into nitin values (4, "A");
    insert into nitin values (5, "B");
    insert into nitin values (6, "B");
    insert into nitin values (7, "B");
    insert into nitin values (8, "C");
    insert into nitin values (9, "C");
    insert into nitin values (10, "C");

    Query:
    select nm,decode (name, "A","Y","B","X","C","Z") from nitin
    order by 2

    Result:
    nm (expression)

    6 X
    5 X
    7 X
    3 Y
    4 Y
    2 Y
    1 Y
    8 Z
    9 Z
    10 Z


    I hope, this is what you want.

    regards,

    Nitin

  3. #3
    Join Date
    May 2004
    Location
    New York
    Posts
    248
    Thank you very much, exactly what I needed

Posting Permissions

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