View previous topic :: View next topic |
Author |
Message |
Sarangadhar Beginner
Joined: 14 Oct 2004 Posts: 130 Topics: 43 Location: virtual village
|
Posted: Tue Oct 30, 2007 4:03 pm Post subject: ORDER BY non-alphetical order |
|
|
I would like to retrieve the rows in a specific order of the values of a given column.
column1 will only contain one of the below given values, at any time:
AA,YY,RR,BB,KK.
I would like to retrieve the rows in the order of RR, YY, BB, AA, KK. Is it possible to retrieve in this specific oeder other than alphebetic order? _________________ Thanks |
|
Back to top |
|
|
danm Intermediate
Joined: 29 Jun 2004 Posts: 170 Topics: 73
|
Posted: Wed Oct 31, 2007 8:16 am Post subject: |
|
|
Code: |
SELECT
CASE COL1
WHEN 'RR' THEN 1
WHEN 'YY' THEN 2
WHEN 'BB' THEN 3
WHEN 'AA' THEN 4
ELSE 5
END AS DUMMY,
COL1, COL2, ......
ORDER BY DUMMY
|
|
|
Back to top |
|
|
Bill Dennis Advanced
Joined: 03 Dec 2002 Posts: 579 Topics: 1 Location: Iowa, USA
|
Posted: Wed Oct 31, 2007 1:17 pm Post subject: |
|
|
A shining example of why I love the knowledgeable users at this site. _________________ Regards,
Bill Dennis
Disclaimer: My comments on this foorum are my own and do not represent the opinions or suggestions of any other person or business entity. |
|
Back to top |
|
|
Sarangadhar Beginner
Joined: 14 Oct 2004 Posts: 130 Topics: 43 Location: virtual village
|
Posted: Thu Nov 01, 2007 6:00 pm Post subject: |
|
|
Thanks danm. nice one. _________________ Thanks |
|
Back to top |
|
|
acevedo Beginner
Joined: 03 Dec 2002 Posts: 127 Topics: 0 Location: Europe
|
Posted: Fri Nov 02, 2007 2:13 am Post subject: |
|
|
BTW, you don't need to give the DUMMY name, I mean:
Code: |
SELECT
CASE COL1
WHEN 'RR' THEN 1
WHEN 'YY' THEN 2
WHEN 'BB' THEN 3
WHEN 'AA' THEN 4
ELSE 5
END
,COL1,
,COL2......
ORDER BY 1
|
|
|
Back to top |
|
|
|
|