postgresql - How to select all tuples determined id and newest timestamp -


given table:

id | timestmap | ..otherstuff.. 

with primary key (id,timestmap). id of type integer , timestamp timestamp.

how can extract tupes of timestamp newest tuple?

e.g. if current data:

1 | 1999-05-23 0:00 | ... 2 | 2000-05-23 0:00 | ... 1 | 2000-06-22 0:00 | ... 

i want result (though order bonus not care for)

1 | 2000-06-22 0:00 | ... 2 | 2000-05-23 0:00 | ... 

for cases use window functions.

as example assuming table called foo, query work:

with tmp (     select id, timestmap, rank() on (partition id order timestmap desc) foo ) select id, timestmap tmp rank=1; 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -