SELECT *
FROM `db_images` AS `i1`
JOIN `db_images` AS `i2` ON `i1`.`image_hash` = `i2`.`image_hash`
AND `i1`.`image_id` != `i2`.`image_id`
JOIN `db_apartments_images_links` AS `a1` ON `a1`.`image_id` = `i1`.`image_id`
JOIN `db_apartments_images_links` AS `a2` ON `a2`.`image_id` = `i2`.`image_id`
AND `a1`.`apartment_id` = `a2`.`apartment_id`