On Fri, Nov 28, 2003 at 16:22:19 +0100,
christoph.dellavalle@goetheanum.ch wrote:
> Hi there
>
> I'm trying to compact an imported table. Any suggestions how this can be done:
>
> Table now:
>
> ID attr1 attr2
> 1 5 NULL
> 1 NULL 7
> 2 8 NULL
> 3 NULL 4
> 4 NULL NULL
>
> The Result should look like this:
>
> ID attr1 attr2
> 1 5 7
> 2 8 NULL
> 3 NULL 4
> 4 NULL NULL
>
>
> Thanks for every hint.
You need to figure out what your rule is for merging rows with the same id.
If you just don't want nulls and don't care which of several nonnull values
you grab, you could do something like:
select a.id, a.attr1, b.attr2 from
(select distinct on (id) id, attr1 where attr1 is not null) as a
full join
(select distinct on (id) id, attr2 where attr2 is not null) as b
using (id);