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

Home -> Community -> Usenet -> c.d.o.server -> Re: SQL Order

Re: SQL Order

From: Lucas <Lucas_44_at_hotmail.com>
Date: Mon, 16 Sep 2002 18:07:18 GMT
Message-ID: <q5ph9.3886$pa1.441458@news0.telusplanet.net>


Ok sounds good so far, but how do I incorporate

 select emp.*,decode(emp,603,1,648,2,810,3,974,4) srt  from Emp

into a much bigger sql? If I add

 select emp.*,decode(emp,603,1,648,2,810,3,974,4) srt,  more sql,
from emp, moretables

I get an error.....

"TurkBear" <john.greco_at_dot.state.mn.us> wrote in message news:qh5cou02qj0s5bmh45jf8tu7qmcufq7qan_at_4ax.com...
> It is not in the order of those codes because you did not ask it to 'order
by ' anything..
> If empcode is a number then you can order by empcode, but that will result
in
> 603
> 648
> 810
> 974
> ( you can use DESC and reverse that order ).
>
> To get the explicit order according to their place in the IN list you
will need to create a dummy column with
> decode and place them in the order you want:
>
> select emp.*,decode(emp,603,1,648,2,810,3,974,4) srt
> from Emp
> where empcode in (810,974,603,648)
> ORDER by srt;
>
> Prior to running this you can issue a
> column srt noprint
> in SqlPlus
> to supress the output from the dummy column.
>
>
>
>
> "Lucas" <Lucas_44_at_hotmail.com> wrote:
>
> >Hi all,
> >
> >I want my query result to be in the same order as my codes that I set:
> >
> >Ex:
> >
> >select * from
> >Emp
> >where empcode in (810,974,603,648)
> >
> >The result is not at all in this order? Any suggestions on why? Or is
there
> >a better way of doing this?
> >
> >
> >Lucas
> >
> >
>
>
>
> -----------== Posted via Newsfeed.Com - Uncensored Usenet News
==----------
> http://www.newsfeed.com The #1 Newsgroup Service in the World!
> -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers
=----- Received on Mon Sep 16 2002 - 13:07:18 CDT

Original text of this message

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