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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ce60c4f78a63b0695e4dafc4bd7964f7?d=identicon&s=25 vanek (Guest)
on 2005-11-13 15:56
(Received via mailing list)
this combines the two into one sql query (assuming the db you are using
can handle subselects):

SELECT products.name, builds.version, builds.install_date
  FROM  builds
  INNER JOIN products ON builds.product_id = products.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.