SELECT
`Ob`.`id` AS `id`,
`Ob`.`title` AS `title`,
(D.count_details + MA.count_materials) as count_items,
GREATEST(MA.last_update, Ob.last_update, D.last_update) as last_update
FROM game.`Object` Ob
JOIN (SELECT objectId, count(*) AS count_details, Max(gD.last_update) as last_update
FROM game.Details AS gD
WHERE gD.status = 1
GROUP BY gD.objectId
) AS D ON D.objectId = Ob.`id`
JOIN (SELECT objectId, count(*) AS count_materials, Max(gM.last_update) as last_update
FROM game.Materials AS gM
WHERE gM.status = 1
GROUP BY gM.objectId
) AS MA ON MA.objectId = Ob.`id`
WHERE Ob.status = 1
ORDER BY last_update DESC
;
RENAME USER ‘root’@'localhost' TO ‘root’@'127.0.0.1';