select t2.id, t4.name as project,t2.name as execution,t3.status from TABLE_PROJECTSTORY as t1 
left join TABLE_EXECUTION as t2 on t1.project=t2.id 
left join TABLE_STORY as t3 on t1.story=t3.id 
left join TABLE_PROJECT as t4 on t4.id=t2.project
where t2.deleted='0' and t2.type in('sprint', 'stage') and if($project='',1,t4.id=$project) and if($execution='',1,t2.id=$execution) and if($status='',1,t2.status=$status)