Re: Select latest Timestamp values with group by

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Adarsh Sharma <adarsh(dot)sharma(at)orkash(dot)com>
Cc: pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Select latest Timestamp values with group by
Date: 2011-10-11 04:58:04
Message-ID: 4E93CCDC.1000707@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 11/10/11 12:55, Adarsh Sharma wrote:
> Thanks Craig, but I solved the issue by the below query :-
>
> Here is the query for that :-
>
> select bb_id,lat,lon,speed,dt_stamp from demo_table
> inner join
> (select bb_id as did, max(dt_stamp) as ts
> from demo_table group by bb_id) as ds
> on demo_table1.bb_id = ds.did and demo_table1.dt_stamp = ds.ts;

Yep, so you used the self-join method. That works, though it's probably
quite a lot slower than using a window function for the job.

I'm glad you found a suitable solution for your needs.

--
Craig Ringer

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2011-10-11 05:04:44 Re: Postgres 9.01, Amazon EC2/EBS, XFS, JDBC and lost connections
Previous Message Adarsh Sharma 2011-10-11 04:55:10 Re: Select latest Timestamp values with group by