我有一个类似推特的网站,用户可以关注其他用户,我需要向他们展示关注新人的建议。
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)关注了4、5、6(D、E、F)。
我收到了显示被关注用户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
我该如何显示未被C(3)关注的用户,换句话说是1、2(A、B)?
我需要使用
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.