SELECT pha.id, pha.project_id, pha.order_num, pha.status, pha.name, pha.date_start, pha.date_end, pha.comments, ( SELECT COUNT( tas1.id ) FROM netoffice_tasks tas1 WHERE tas1.project = pha.project_id AND tas1.parent_phase = pha.order_num AND tas1.milestone != '0' AND tas1.level = '0' ), ( SELECT COUNT( tas2.id ) FROM netoffice_tasks tas2 WHERE tas2.project = pha.project_id AND tas2.parent_phase = pha.order_num AND tas2.status & lt ; & gt; '1' AND tas2.milestone != '0' AND tas2.level = '0' ), ( SELECT COUNT( tas3.id ) FROM netoffice_tasks tas3 WHERE tas3.project = pha.project_id AND tas3.parent_phase = pha.order_num AND tas3.milestone = '0' AND tas3.level = '0' ) FROM netoffice_phases pha WHERE pha.project_id = '1' ORDER BY pha.order_num ASC