MySql - Combine records based on foreign key

I have records in my DB like the following image. I want to get the highlighted records only.The full query is below:

 select `holybharat_temple_media`.`id`, 
`holybharat_temple_media`.`temple_id`,
 `holybharat_temple_media`.`media_path`, `holybharat_temple_history`.`category_description`,
 `temple_name`, `lattitude`, `longitude`,
 `holybharat_state_master`.`state`, 
`holybharat_city_master`.`city`,
 `pincode` 
from `holybharat_temple_master`
 left join `holybharat_city_master` on `holybharat_temple_master`.`city` = `holybharat_city_master`.`id`
 left join `holybharat_state_master` on `holybharat_temple_master`.`state` = `holybharat_state_master`.`id`
 left join `holybharat_temple_media` on `holybharat_temple_master`.`id` = `holybharat_temple_media`.`temple_id`
 left join `holybharat_temple_history` on `holybharat_temple_master`.`id` = `holybharat_temple_history`.`temple_id`
 where `holybharat_temple_master`.`id` in (5,6,7,8,9) and `holybharat_temple_history`.`category_type` = 'history'

enter image description here