SELECT DISTINCTROW `p` . `id` , `p` . `name` , `ph` . `parent_id` FROM `mantis_project_table` `p` LEFT JOIN `mantis_project_hierarchy_table` `ph` ON `ph` . `child_id` = `p` . `id` WHERE `ph` . `parent_id` IS NOT NULL ORDER BY `p` . `name` 