Querying most recent value with GLORP

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Querying most recent value with GLORP

Esteban A. Maringolo
I'm resending this mail to Pharo-Users with the hope somebody will
reply (I got no single reply in the GLORP mailing list)


I want to retrieve the most recent values using GLORP.

Ej:

myTable
date    entity_id
1/6/13  1
1/10/13 1
1/7/13  2
1/1/14  2

SELECT *
  FROM myTable
  WHERE (entity_id, date)
    IN (SELECT entity_id, max(date) from myTable WHERE DATE <=
'2014-01-01' GROUP BY entity_id)

This would bring:

date    entity_id
1/10/13 1
1/1/14  2

Or in the case I want it for a specific entity:

SELECT *
  FROM myTable
  WHERE (entity_id, date)
    IN (SELECT entity_id, max(date) from myTable WHERE DATE <=
'2014-01-01' AND entity_id = 1 GROUP BY entity_id)

Result:
date    entity_id
1/10/13 1


Is there a way I can do this using a Glorp Query?


Regards,

Esteban A. Maringolo