I have the following, simplified table:
| id | order_id | created_at |
| 1 | 1 | 2011-07-11 |
| 2 | 1 | 2011-07-12 |
| 3 | 2 | 2011-07-13 |
| 4 | 2 | 2011-07-14 |
Now i'm trying to get all records for a list of orders, but only the latest one for each order_id
EdpuOrder.find(:all, :conditions => "edpu_orders.order_id IN (#{ids})", :order => "edpu_orders.created_at")
The ids variable is generated by a subquery, let's say it's "1, 2" for now. The statement above should return the records 2 and 4. Any ideas?