pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stefan Becker <pgsql@yukonho.de>
To: pgsql-sql@postgresql.org
Subject: Re: Selecting exactly one row for each column value
Date: Tue, 6 Mar 2007 19:14:49 +0100
Message-ID: <200703061914.50151.pgsql@yukonho.de> (raw)
In-Reply-To: <82hcsy4do7.fsf@mid.bfk.de>
References: <82hcsy4do7.fsf@mid.bfk.de>

Am Dienstag, 6. März 2007 16:03 schrieb Florian Weimer:

>  a | b | c
> ---+---+---
>  5 | 6 | 7
>  2 | 3 | 4
>  1 | 2 | 3

Hi,
couldn't you accomplish this by:

select distinct on (a) * from tablename order by a;


here:

create table tab (a int,b int,c int);
insert into tab values (1,2,3);
insert into tab values (5,6,7);
insert into tab values (1,2,3);
insert into tab values (2,3,4);
insert into tab values (1,2,2);
insert into tab values (2,3,4);

select * from tab;
 a | b | c
---+---+---
 1 | 2 | 3
 5 | 6 | 7
 1 | 2 | 3
 2 | 3 | 4
 1 | 2 | 2
 2 | 3 | 4
(6 rows)

select distinct on (a) * from tab order by a;
 a | b | c
---+---+---
 1 | 2 | 3
 2 | 3 | 4
 5 | 6 | 7
(3 rows)



my regards,


Stefan






-- 
email: stefan@yukonho.de
tel  : +49 (0)6232-497631
http://www.yukonho.de



view thread (5+ messages)

Message-ID: <200703061914.50151.pgsql@yukonho.de>
Permalink:  ../200703061914.50151.pgsql@yukonho.de/
Also on:    postgresql.org/message-id/200703061914.50151.pgsql@yukonho.de

 · 

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: pgsql@yukonho.de
  Subject: Re: Selecting exactly one row for each column value
  In-Reply-To: <200703061914.50151.pgsql@yukonho.de>

* 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