Re: SQL-Statment

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: christoph(dot)dellavalle(at)goetheanum(dot)ch
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: SQL-Statment
Date: 2003-11-28 16:31:20
Message-ID: 20031128163120.GA21543@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Fri, Nov 28, 2003 at 16:22:19 +0100,
christoph(dot)dellavalle(at)goetheanum(dot)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);

In response to

  • SQL-Statment at 2003-11-28 15:22:19 from christoph.dellavalle

Browse pgsql-novice by date

  From Date Subject
Next Message Anis W. Nugroho 2003-11-28 16:48:21 Re: Environment variables
Previous Message christoph.dellavalle 2003-11-28 15:22:19 SQL-Statment