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: SQL question

Re: SQL question

From: Paul Koppens <pkoppens_at_dstm.nl>
Date: 20 May 1998 21:13:30 GMT
Message-ID: <01bd8434$3567c1c0$073ff161@pko.ntdom1>


Hi Michael,

Actually, it's easier than what you tried:

select Col_A, Col_B

        , decode(Col_A,
                      Col_B, 0,
                      1) Col_Different_Or_Not
from ...

So when Col_A equals Col_B, you select 0; otherwise, you select 1. However, adding a column to reflect the difference between Col_A and Col_B would be poor database design: it's a denormalization which you'll have to maintain whenever Col_A or Col_B change. If you need to present 'Col_Different_Or_Not' separately, consider creating a view defined as the above select statement.

good luck,

Paul.

hsiwei yu <yu.michael_at_epamail.epa.gov> wrote in article <6juomj$lkc1_at_valley.rtpnc.epa.gov>...
> Hi,
>
> a newbie question:
>
> have a table with two columns
> Col_A Col_B
> ==============
> vv yyy
> qq qq
> zz zz
>
> How to create an additional column
> Col_A Col_B Different_A_B_Or_Not
> =================================
> vv yyy 1
> qq qq 0
> zz zz 0
>
> Here's what I have tried (& won't work)
> select Col_A, Col_B
> , decode(( Col_A != Col_B )
> , 0, 0
> , 1, 1
> , NULL ) as Col_Different_Or_Not
> from ...
>
> Need your help, thanks,
>
> Michael
>
>
>
Received on Wed May 20 1998 - 16:13:30 CDT

Original text of this message

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