SELECT a.*, SUM( rh.hits ) AS rhhits, CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug, CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug FROM #__recordhits AS rh LEFT JOIN #__content AS a ON a.id = rh.id_article LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id INNER JOIN #__categories AS cc ON cc.id = a.catid INNER JOIN #__sections AS s ON s.id = a.sectionid WHERE ( a.state = 1 AND s.id > 0 ) AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '2012-05-23 14:55:01' ) AND ( rh.date >= '2012-04-22' ) AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '2012-05-23 14:55:01' ) AND s.published = 1 AND cc.published = 1 GROUP BY a.id ORDER BY rhhits DESC LIMIT 10