postgresql7.1 select survey_response__initial_response_id(:response_id) as initial_response_id select max(response_id) as response_id,count(*) as unfinished from survey_responses r inner join acs_objects o on (r.response_id=o.object_id) where finished_p='f' and creation_user=:user_id and survey_id=:survey_id