Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Re: sort by decode in union all
In article <9ZbY4.11$CH4.1905_at_news.flash.net>,
"Peter Chang" <jchang_at_flash.net> wrote:
> Hi,
> I have a query like select a.empno empno,
> a.status status,
> a.sallary sal
> from table_a a
> union
> select b.empno empno,
> b.status status,
> b.sallary sal
> from table_b b
> order by 2,1,3 ----------- I know do
> that
>> &p,1,'status',2,empno,sallary)
> But how do you do order by (decode
>
You have to put your decode into select clause of both selects in union, then use order by 4. If you don't want that decode to be printed (I suppose it's sqlplus), then you can do:
column ord_col noprint
select a.empno empno,
a.status status, a.sallary sal, decode(&p,1,status,2,empno,sallary) ord_col from table_a a
b.status status, b.sallary sal decode(&p,1,status,2,empno,sallary) ord_colfrom table_b b
I hope sallary and status have the same datatype.
Alex Filonov
>
Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Wed May 31 2000 - 00:00:00 CDT
![]() |
![]() |