HI I have the following query:
SELECT PAS_User.user_user_id,
PAS_User.user_city,
PAS_User.user_company,
PAS_User.user_country,
PAS_User.user_account_type,
PAS_User.user_account_premium,
PAS_User.user_sign_up_date,
PAS_User.user_first_name,
PAS_User.user_last_name,
PAS_User.user_avatar_url,
PAS_User.user_cover_image_url,
PAS_User.user_bio,
PAS_User.user_sector,
PAS_User.user_job_type,
(SELECT COUNT(*) FROM `PAS_Follow` WHERE `folw_follower_user_id`=:sid) AS user_following_count,
(SELECT COUNT(*) FROM `PAS_Follow` WHERE `folw_followed_user_id`=:sid) AS user_followed_count,
(SELECT COUNT(*) FROM `PAS_Post` WHERE `post_user_id`=:sid) AS user_post_count,
(SELECT COUNT(*) FROM `PAS_Follow` WHERE `folw_follower_user_id`=:sid AND `folw_followed_user_id`=:cid) AS user_this_user_is_following,
(SELECT COUNT(*) FROM `PAS_Follow` WHERE `folw_followed_user_id`=:cid AND `folw_follower_user_id`=:sid) AS user_this_user_is_followed
FROM PAS_User
WHERE `PAS_User`.`user_user_id`=:sid
Which is designed to get counts from other tables for a profile page and the basic user details where :sid = 1 and :cid = 2.
The question is, is there any better way of achieving this in perhaps a smaller query or in a cleaner way?
The tables used are
PAS_User , PAS_Follow & PAS_Post
Thanks
Justin