Re: Select latest Timestamp values with group by - Mailing list pgsql-general

From Craig Ringer
Subject Re: Select latest Timestamp values with group by
Date
Msg-id 4E93CCDC.1000707@postnewspapers.com.au
Whole thread Raw
In response to Re: Select latest Timestamp values with group by  (Adarsh Sharma <adarsh.sharma@orkash.com>)
List 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

pgsql-general by date:

Previous
From: Craig Ringer
Date:
Subject: Re: Postgres 9.01, Amazon EC2/EBS, XFS, JDBC and lost connections
Next
From: Raghavendra
Date:
Subject: Re: Help on PostgreSQL