Re: filtering out doubles - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: filtering out doubles
Date
Msg-id 20030312121542.F55615-100000@megazone23.bigpanda.com
Whole thread Raw
In response to filtering out doubles  ("Jules Alberts" <jules.alberts@arbodienst-limburg.nl>)
List pgsql-sql
On Wed, 12 Mar 2003, Jules Alberts wrote:

> Hello everyone,
>
> I was wondering how to filter out double values (where "value" spans
> two columns COL1 and COL2) with a SELECT statement. If I have this
> table:
>
> COL1 |COL2 |COL3
> -----------------------------
> a    |b    |some value
> a    |b    |another value
> a    |c    |yet another value
>
> what would be the select statement to get this result:
>
> COL1 |COL2 |COL3
> -----------------------------
> a    |b    |some value
> a    |c    |yet another value
>
> I was thinking that DISTINCT would do this, but I don't want to loose
> COL3. TIA for any tips!

If you're willing to use a postgresql extension,
select distinct on (col1, col2) * ...

That'll give you a pretty much arbitrarily chosen col3 for a col1,col2
pair that has duplicates. You can get some control over which one is
chosen using order by IIRC.




pgsql-sql by date:

Previous
From: "Jon Griffin"
Date:
Subject: Re: Create function statement with insert statement
Next
From: Tomasz Myrta
Date:
Subject: Re: LEFT JOIN and missing values