SELECT `deal_page_tab_set`.`deal_page_tab_set_id` , `deal_page_tab`. * , `tabCategory`.`tab-category` AS tabCategory , `deal_page_group_name`.`name` AS `group_name` FROM `dailyDeal` JOIN `dailyDeal_tabCategory` ON `dailyDeal_id` = `dailyDeal`.`id` JOIN `tabCategory` ON `tabCategory`.`id` = `tabCategory_id` LEFT JOIN `deal_page_tab_set` ON `tabCategory`.`tab-category` = `deal_page_tab_set`.`deal_tab_name` LEFT JOIN `deal_page_tab` ON `tabCategory`.`tab-category` = `deal_page_tab`.`tab_name` LEFT JOIN `deal_page_group_name` on `deal_page_group_name`.`deal_page_tab_group_id`=`deal_page_tab_set`.`deal_page_tab_set_id` WHERE `tabCategory`.`tab-category` LIKE '%Primary School%' AND `deal_page_tab_set_id` IS NOT NULL AND `dailyDeal`.`published`=1 GROUP BY `tab-category`