I have a twiter-like web, where users follow another users, I need to show them suggestions to follow new people
TABLE USERS
user id_user
A 1
B 2
C 3
D 4
E 5
F 6
TABLE COMMUNITY
id_follower id_followed
3 4
3 5
3 6
3 (C) follows to 4,5,6 (D,E,F)
I got the statement of showing the followed users, 4,5,6 (D,E,F):
SELECT user,id_followed
FROM users,community
WHERE users.id_user=community.id_followed AND community.id_follower=3
GROUP BY user
How do I show the users that arent followed by C(3), in other words 1,2 (A,B)
Do I need an EXCEPT
? LEFT OUTER JOIN
?
SELECT id_followed
FROM community
EXCEPT
(
SELECT user,id_followed
FROM users,community
WHERE users.id_user=community.id_followed AND community.id_follower=3
GROUP BY user
)
RETRIEVE ERROR.