Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: SQL Order
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 - 12:43:39 CDT