Re: combine rows dependent on match two columns

From: Shakespeare <whatsin_at_xs4all.nl>
Date: Tue, 10 Mar 2009 14:50:03 +0100
Message-ID: <49b66fe9$0$184$e4fe514c_at_news.xs4all.nl>



NOVA schreef:
> Dear all,
>
> If I have table like this
>
> A aa B bb
> 1 5
> 2 7
> 1 7
> 3 6
>
>
> I want to make the result like this
>
> A or B aa bb
> 1 5 7
> 2 7
> 3 6
>
>
> A or B is a column has all data avaliable in both A and B
>
>
> help please
>
>

I'm sure there are better ways, but how about

select distinct nvl(t1.a,t2.b), t1.aa, t2.bb from example t1, example t2 where t1.a=t2.b

or ( t1.a is null and t2.b is not null and not exists (select 1 from 
example t3 where t3.a=t2.b))
or ( t2.b is null and t1.a is not null and not exists (select 1 from 
example t4 where t1.a=t4.b))

Shakespeare Received on Tue Mar 10 2009 - 08:50:03 CDT

Original text of this message