SELECT `p` . `id` , `p` . `name` , `ph` . `parent_id` FROM `mantis_project_table` `p` LEFT JOIN `mantis_project_user_list_table` `u` ON `p` . `id` = `u` . `project_id` AND `u` . `user_id` = ? LEFT JOIN `mantis_project_hierarchy_table` `ph` ON `ph` . `child_id` = `p` . `id` WHERE ( `p` . `view_state` = ? OR ( `p` . `view_state` = ? AND `u` . `user_id` = ? ) ) ORDER BY `p` . `name` 