Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Oracle Sort but not constrainted

Re: Oracle Sort but not constrainted

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Fri, 09 Apr 1999 15:03:31 GMT
Message-ID: <37101661.14002614@192.86.155.100>


A copy of this was sent to sknott_deja_at_my-dejanews.com (if that email address didn't require changing) On Fri, 09 Apr 1999 14:36:17 GMT, you wrote:

>Hi,
>
>I am attempting to do a query of an airline database like:
>
>Flight_Id Number(5)
>Airline Varchar(2)
>Depart_Date Number(8)
>Dapart_Time Number(4)
>
>select * from airline_flights where Depart_Date = 19990410;
>
>But I need to sort the Airline Codes by a specified list which
>may be different each time I do a query. For example, I do the
>above query, but want codes 'NW' and 'UA' to be at the top of the
>table. Next query might need 'US' at the top.
>

decode might help.

select * from airline_flights where Depart_Date = 19990410 order by decode( airline, 'US', 1, 2 ), airline;

would order the result set with US first and the all others by airline code after that.

select * from airline_flights where Depart_Date = 19990410 order by decode( airline, 'NW', 1, 'UA', 1, 2 ), airline;

That would put NW and UA first and then all others after that...

>Is this possible? If so, can someone head me in the right direction?
>
>Thanks,
>Steve K.
>
>-----------== Posted via Deja News, The Discussion Network ==----------
>http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
 

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Service Industries
Reston, VA USA

--
http://govt.us.oracle.com/ -- downloadable utilities  



Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Fri Apr 09 1999 - 10:03:31 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US