If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > sort question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-29-06, 10:10
artemka artemka is offline
Registered User
 
Join Date: May 2004
Location: New York
Posts: 248
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
Reply With Quote
  #2 (permalink)  
Old 06-30-06, 03:29
nitin_math nitin_math is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 07-06-06, 13:16
artemka artemka is offline
Registered User
 
Join Date: May 2004
Location: New York
Posts: 248
Thank you very much, exactly what I needed
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On