I got a table like this
Measurements
id object_id generated_at (v)
110 4 2012-11-13 10:29:00
109 4 2012-11-13 10:28:00
108 4 2012-11-13 10:27:00
107 3 2012-11-13 10:26:00
106 3 2012-11-13 10:25:00
105 4 2012-11-13 10:24:00
104 4 2012-11-13 10:23:00
103 1 2012-11-13 10:22:00
102 1 2012-11-13 10:21:00
...
ordered by generated_at column.
My question: is there any ability to select
id object_id generated_at (v)
110 4 2012-11-13 10:29:00
109 4 2012-11-13 10:28:00
108 4 2012-11-13 10:27:00
last group(ordered by generated_at) of measurements with same object_id ?
It could be example in rails for Measurement model or just SQL query, thanks for any help!
You original question clearly wanted the objects in the most recent groups, not all objects. For this, you need to calculate both the max object id and the maximum generated time for other objects: