You can try this (without data it is hard to test)
SELECT r.*, COUNT(c.id)
FROM tbl_rls r, comments c, tbl_visitors_logs v, tbl_cats t
WHERE c.post_id = r.id
AND v.rls_id = r.id
AND t.parent_id = r.cat
AND r.status <> 'denied'
AND v.`date` LIKE '2010-07-02%'
AND page_type = 'post'
AND cat = 6 OR t.parent_id = 6
GROUP BY c.post_id
ORDER BY r.`date` DESC
LIMIT 0, 20
Is this data structure correct?
CREATE TABLE IF NOT EXISTS `tbl_cats` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`parent_id` int(11) NOT NULL,
`name` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `tbl_rls` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`status` varchar(10) NOT NULL,
`cat` int(11) NOT NULL,
`date` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `tbl_visitors_logs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`rls_id` int(11) NOT NULL,
`date` date NOT NULL,
`page_type` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `comments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`post_id` int(11) NOT NULL,
`commetn` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;