SELECT `o`.`id` AS `object_id`, `o`.`data` AS `object_data`, `m`.*, `ms`.`name` AS `status_name` FROM `sys_objects` AS `o`
 LEFT JOIN `sys_messages_links` AS `ml` ON ml.value_id = o.id
 LEFT JOIN `sys_messages` AS `m` ON m.id = ml.message_id
 LEFT JOIN `sys_messages_statuses` AS `ms` ON m.status_id = ms.id
 LEFT JOIN `sys_messages_properties` AS `mp` ON mp.name = "rating"
 LEFT JOIN `sys_messages_properties_values_int` AS `mpv` ON m.id = mpv.messages_id AND mpv.property_id=mp.id
 LEFT JOIN `sys_messages_properties_values_int` AS `mpvOrder` ON m.id = mpvOrder.messages_id AND mpvOrder.property_id=17
 LEFT JOIN `sys_orders` AS `or` ON or.id = mpvOrder.value WHERE (o.visible = '1') AND (o.status_id in (1, 2, 3)) AND (ml.module = 'objects') AND (m.visible = '1') AND ((SELECT ml.value_id FROM sys_messages mes
				INNER JOIN sys_messages_links ml ON ml.message_id = mes.id AND module = "orders"
				WHERE mes.type_id = 5 AND status_id = 3 AND ml.value_id = mpvOrder.value) IS NOT NULL OR or.date_end < DATE_ADD(NOW(), INTERVAL - 5 DAY) OR or.id IS NULL) AND (m.type_id IN (3, 8)) AND (m.status_id = 3) AND (o.id = 28017) ORDER BY `mpv`.`value` DESC, `m`.`id` DESC LIMIT 6