Re: Selecting exactly one row for each column value - Mailing list pgsql-sql

From Stefan Becker
Subject Re: Selecting exactly one row for each column value
Date
Msg-id 200703061914.50151.pgsql@yukonho.de
Whole thread Raw
In response to Selecting exactly one row for each column value  (Florian Weimer <fweimer@bfk.de>)
List pgsql-sql
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 | 35 | 6 | 71 | 2 | 32 | 3 | 41 | 2 | 22 | 3 | 4
(6 rows)

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



my regards,


Stefan






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


pgsql-sql by date:

Previous
From: "Ezequias Rodrigues da Rocha"
Date:
Subject: Re: Inc
Next
From: Richard Huxton
Date:
Subject: Re: Inc