Forum: Ruby on Rails Re: finding the latest date + start with DB first?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
vanek (Guest)
on 2005-11-13 16:56
(Received via mailing list)
this combines the two into one sql query (assuming the db you are using
can handle subselects):

SELECT, builds.version, builds.install_date
  FROM  builds
  INNER JOIN products ON builds.product_id =,
    (SELECT builds.product_id, MAX(builds.install_date) AS dt
       FROM builds
      GROUP BY 1) AS x
WHERE builds.product_id = x.product_id
   AND builds.install_date = x.dt

[This was tested on MySQL 4.1.12]
This topic is locked and can not be replied to.