select t1.id,t1.name,t2.status,t2.project,t2.id as taskID, if($status='','', t1.status) as projectstatus from TABLE_PROJECT as t1 left join TABLE_TASK as t2 on t1.id=t2.project where t1.deleted='0' and t2.deleted='0' and t1.begin>=$beginDate and end<=$endDate having projectstatus=$status