Re: [SQL] Select every first/last record of a partition?

2012-05-21 Thread Seth Gordon
I think this would work: select distinct on (id) id, ts --and whatever other columns you want from mytab order by id, timestamp desc; On Mon, May 21, 2012 at 12:04 PM, Andreas wrote: > Hi, > > suppose a table that has records with some ID and a timestamp. > > id,    ts > 3,    2012/01/03 > 5,  

[SQL] Select every first/last record of a partition?

2012-05-21 Thread Andreas
Hi, suppose a table that has records with some ID and a timestamp. id,ts 3,2012/01/03 5,2012/01/05 7,2012/01/07 3,2012/02/03 3,2012/01/05 5,2012/03/01 7,2012/04/04 to fetch every last row of those IDs I do: select id, ts from ( select id, ts, row_number(

Re: [SQL] master/detail

2012-05-21 Thread Mario Dankoor
On 2012-05-21 1:17 AM, Jan Bakuwel wrote: Hi, I'm trying to get my head around the following question. As an example take a table with products: productid (pk) name and productprice productpriceid (pk) productid (fk) pricedate price There are multiple records in productprice for each product