下面是我的SQL查询
SELECT individuals.* FROM ( select children.* FROM checkins, children WHERE checkins.child_id = children.id AND checkins.event_id = 1234 ) temp, individuals WHERE temp.individual_id = individuals.id ORDER BY individuals.firstname;
可以将其转换为rails 2.3.5兼容(活动记录查找方法)
[编辑]
SELECT individuals.* FROM ( SELECT children.* FROM checkins INNER JOIN children ON checkins.child_id = children.id WHERE checkins.event_id = 1234 ) temp INNER JOIN individuals ON temp.individual_id = individuals.id ORDER BY individuals.firstname;
答案 0 :(得分:1)
Individual.find(:all, :joins => {:children => :checkins}, :conditions => 'checkins.event_id = 1234', :order => 'individuals.firstname')