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 <= '2010-08-17 17:58:43' ) AND ( rh.date >= '2010-08-10' ) AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '2010-08-17 17:58:43' ) AND a.access <= 0 AND cc.access <= 0 AND s.access <= 0 AND s.published = 1 AND cc.published = 1 GROUP BY a.id ORDER BY rhhits DESC LIMIT 10