SELECT
(
SELECT COUNT(*)
FROM `engine4_activity_actions`
INNER JOIN `engine4_activity_likes` ON `engine4_activity_likes`.resource_id = `engine4_activity_actions`.action_id
WHERE `engine4_activity_likes`.poster_id != `engine4_activity_actions`.object_id
AND `engine4_activity_actions`.object_id = 3
) + (
SELECT COUNT(*)
FROM `engine4_core_likes`
WHERE `engine4_core_likes`.user_id = 3
)
AS likes_total;
$tableActivityActions = Engine_Api::_()->getDbTable('actions', 'activity');
$tableActivityActionsName = $tableActivityActions->info('name');
$tableActivityLikes = Engine_Api::_()->getDbTable('likes', 'activity');
$tableActivityLikesName = $tableActivityLikes->info('name');
$tableCoreLikes = Engine_Api::_()->getDbTable('likes', 'core');
$tableCoreLikesName = $tableCoreLikes->info('name');
// get sub-select from first table
$selectCoreLikes = $tableCoreLikes->select()
->from($tableCoreLikesName, array('COUNT(*)'))
->where("$tableCoreLikesName.user_id = ?", $user_id)
;
// get sub-select from second table
$selectActivityLikes = $tableActivityActions->select()
->from($tableActivityActionsName, array('COUNT(*)'))
->join($tableActivityLikesName, "$tableActivityLikesName.resource_id = $tableActivityActionsName.action_id", null)
->where("$tableActivityLikesName.poster_id != $tableActivityActionsName.object_id")
->where("$tableActivityActionsName.object_id = ?", $user_id)
;
$db = $tableCoreLikes->getAdapter();
$selectTotalLikes = $db->query('SELECT (' . $selectCoreLikes->__toString() . ') + ('
. $selectActivityLikes->__toString() . ')');
$result = $selectTotalLikes->fetchAll();
$totalLikes = array_shift($result[0]);