pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chad Thompson <chad@weblinkservices.com>
To: Jules Alberts <jules.alberts@arbodienst-limburg.nl>
To: pgsql-sql@postgresql.org
Subject: Re: filtering out doubles
Date: Wed, 12 Mar 2003 13:03:43 -0700
Message-ID: <0c4901c2e8d2$7c8e6c40$32021aac@chad> (raw)
References: <20030312100410.BBFD01CB1A5@koshin.dsl.systemec.nl>

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.alberts@arbodienst-limburg.nl>
To: <pgsql-sql@postgresql.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
>




view thread (3+ messages)  latest in thread

Message-ID: <0c4901c2e8d2$7c8e6c40$32021aac@chad>
Permalink:  ../0c4901c2e8d2$7c8e6c40$32021aac@chad/
Also on:    postgresql.org/message-id/0c4901c2e8d2$7c8e6c40$32021aac@chad

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: chad@weblinkservices.com, jules.alberts@arbodienst-limburg.nl
  Subject: Re: filtering out doubles
  In-Reply-To: <0c4901c2e8d2$7c8e6c40$32021aac@chad>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox