Re: filtering out doubles

From: "Chad Thompson" <chad(at)weblinkservices(dot)com>
To: "Jules Alberts" <jules(dot)alberts(at)arbodienst-limburg(dot)nl>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: filtering out doubles
Date: 2003-03-12 20:03:43
Message-ID: 0c4901c2e8d2$7c8e6c40$32021aac@chad
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Distinct on is probably your answer.
Something like

select distinct on(col2) col1,col2,col3
from mytable

The traditional disclamer that goes with this is that distinct on is not SQL
standard and is therefore not portable. But it works very well

HTH
Chad

----- Original Message -----
From: "Jules Alberts" <jules(dot)alberts(at)arbodienst-limburg(dot)nl>
To: <pgsql-sql(at)postgresql(dot)org>
Sent: Wednesday, March 12, 2003 3:03 AM
Subject: [SQL] filtering out doubles

> 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!
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message mila 2003-03-12 20:12:15 Re: LEFT JOIN and missing values
Previous Message Jon Griffin 2003-03-12 19:59:12 Re: Create function statement with insert statement