SELECT `p`.*, `g`.`group_name`, GROUP_CONCAT(sc.sub_category_name) as category_name, `u`.`code` as `user_code`, `auth_name` as `user_name`, `u`.`user_image`, `u`.`auth_name`, `u`.`address` as `user_address`, `u`.`email` as `user_email`, `u`.`hometown` as `user_hometown`, `u`.`city` as `user_city`, `u`.`state` as `user_state`, CASE WHEN u.dob IS NOT NULL THEN CONCAT(year(curdate())-year(dob), ' Y') ELSE '' END AS user_age, CASE WHEN gender.gender_short IS NOT NULL THEN gender.gender_short ELSE '' END AS user_gender, CASE WHEN city.name IS NOT NULL THEN city.name ELSE '' END AS city_name, CASE WHEN s.name IS NOT NULL THEN s.name ELSE '' END AS state_name, CASE WHEN county.name IS NOT NULL THEN county.name ELSE '' END AS county_name, CASE WHEN team.name IS NOT NULL THEN team.name ELSE '' END AS team_name, CASE WHEN c.total_comments IS NOT NULL THEN c.total_comments ELSE 0 END AS total_comments, CASE WHEN l.total_likes IS NOT NULL THEN l.total_likes ELSE 0 END AS total_likes, CASE WHEN liked.user_id IS NOT NULL THEN 1 ELSE 0 END AS isLiked, CASE WHEN report_post.post_id IS NOT NULL THEN 1 ELSE 0 END AS isReported, CASE WHEN notify_user_post.from_user IS NOT NULL THEN 1 ELSE 0 END AS isNotificationSubscribed, CASE WHEN bookmark_post.bookmark_post_id IS NOT NULL THEN 1 ELSE 0 END AS isSavedAsBoomark FROM `posts` `p` LEFT JOIN `groups` `g` ON `g`.`group_id`=`p`.`group_id` LEFT JOIN `user` `u` ON `u`.`user_id`=`p`.`user_id` LEFT JOIN `gender` ON `gender`.`gender_id`=`u`.`sex` LEFT JOIN `sub_category` `sc` ON FIND_IN_SET(sc.sub_category_id, p.category_id) > 0 LEFT JOIN `category` ON `category`.`category_id`=`sc`.`category_id` LEFT JOIN `cities` `city` ON `city`.`id`=`p`.`city` LEFT JOIN `states` `s` ON `s`.`id`=`p`.`state` LEFT JOIN `county` ON `county`.`id`=`u`.`county` LEFT JOIN `teams` `team` ON `team`.`id`=`p`.`team` LEFT JOIN (SELECT COUNT(comment_id) as total_comments, post_id FROM post_comments GROUP BY post_id) c ON `c`.`post_id` = `p`.`post_id` LEFT JOIN (SELECT COUNT(user_id) as total_likes, post_id FROM likes GROUP BY post_id) l ON `l`.`post_id`=`p`.`post_id` LEFT JOIN `likes` `liked` ON `liked`.`post_id`=`p`.`post_id` AND `liked`.`user_id`='' LEFT JOIN `blocked` ON `blocked`.`to_user`=`p`.`user_id` AND `blocked`.`from_user`='' LEFT JOIN `notify_user_post` ON `notify_user_post`.`to_user`=`p`.`user_id` AND `notify_user_post`.`from_user`='' LEFT JOIN `bookmark_post` ON `bookmark_post`.`post_id`=`p`.`post_id` AND `bookmark_post`.`user_id`='' LEFT JOIN `report_post` ON `report_post`.`post_id`=`p`.`post_id` AND `report_post`.`user_id`='' LEFT JOIN `delete_post` ON `delete_post`.`post_id`=`p`.`post_id` AND `delete_post`.`user_id`='' LEFT JOIN `connections` `con` ON ((`con`.`from_user`=`p`.`user_id` AND `con`.`to_user`='') OR (`con`.`from_user`='' AND `con`.`to_user`=p.user_id)) AND `con`.`status`=1 WHERE `p`.`parent_id` = 0 AND `p`.`url_category_id` = '20' AND `blocked`.`block_id` IS NULL AND `delete_post`.`delete_post_id` IS NULL AND `p`.`status` = '1' AND `u`.`status` = '1' GROUP BY `p`.`post_id` ORDER BY `p`.`post_id` DESC, `p`.`post_id` DESC LIMIT 5