SELECT c.* FROM `cattree` AS `c` WHERE c.`END_DIMVAL_ID` = '' AND COALESCE(c.`category_page`, '') <> '' GROUP BY c.`dept_id`