Here's one that's been bugging me - anyone want to take a crack at it?
@dev_configs = DeviceConfig.
joins("join (select device_id, max(updated_at) as max_updated_at
from device_configs group by device_id) dc2
on dc2.device_id = device_configs.device_id and
dc2.max_updated_at = device_configs.updated_at").
includes("device").order("devices.updated_at desc")
Each device has many device configurations, and we want to display all devices, along with the latest device configuration, and order the whole thing by when the device was updated. The above works, but is mostly working directly in SQL, rather than with Rails.