select so.*, case when s.single_section_p then '' else ss.name end as section_name from survey_objects so left join survey_sections ss on so.section_id=ss.section_id and ss.section_id <> so.object_id, surveys s where s.survey_id=:object_id and so.survey_id=s.survey_id order by so.object_id select * from survey_objects where section_id=:object_id select * from survey_objects where object_id=:object_id