SELECT p.*, COUNT(l.id) as total_views from abl_posts p LEFT JOIN abl_posts_view_lba l ON (l.post_id = p.ID ) INNER JOIN abl_postmeta pm force index(idx_pm) ON (pm.post_id = p.ID and pm.meta_key = "main_skill" and pm.meta_value = "director") WHERE post_type = 'artist' AND post_status = 'publish' HAVING total_views > 0 ORDER BY total_views DESC limit 100