I have a query:
SELECT b.user_id, b.active FROM users b
WHERE b.followers_count != (SELECT COUNT(*)
FROM (SELECT u.user_id
FROM user_follow uf,users u,user_follow_request ufr
WHERE
uf.following_id = b.user_id AND
uf.following_id = ufr.friend_id AND
ufr.status = 'approved' AND
ufr.user_id = u.user_id AND u.user_id != b.user_id AND u.active != 0
GROUP BY u.user_id) a)
AND b.active = -1 limit 5;
It has to select all the user_id's from users that have different followers_count in the column from the one being calculated by sql. But the problem is that I'm receiving error message 'Error Code: 1054. Unknown column 'b.user_id' in 'on clause' '. What I'm doing wrong? Highly appreciate your help.