SELECT
COUNT(*)
FROM
(SELECT
i.*
FROM
`item` AS `i`
LEFT JOIN `cat_struct` AS `cs` ON (i.cat_id = cs.id)
WHERE
(`i`.`status` = 'active')
AND (`i`.`has_image` = 'yes')
AND (`i`.`type` = 'advert')
AND (`cs`.`lkey` >= '4094')
AND (`cs`.`lkey` <= '4877')
AND (`cs`.`rkey` >= '0')
AND (`cs`.`rkey` <= '4877')
GROUP BY `i`.`id` ORDER BY NULL) AS tbl;
SELECT
COUNT(*)
FROM
`item` AS `i`
LEFT JOIN `cat_struct` AS `cs` ON (i.cat_id = cs.id)
WHERE
(`i`.`status` = 'active')
AND (`i`.`has_image` = 'yes')
AND (`i`.`type` = 'advert')
AND (`cs`.`lkey` BETWEEN '4094'AND '4877')
AND (`cs`.`rkey` BETWEEN '0' AND '4877')
GROUP BY `i`.`id`