获取所有未关注用户的用户2

时间:2017-11-11 01:33:12

标签: php mysql

示例:我想让所有不关注id 2用户的用户

表追随者

   id     |   user_id   |  follower_id

    1            2             7
    2            2             8

表用户

id  |  username  | e-mail  | group

2 个答案:

答案 0 :(得分:0)

我不是mysql专家,但我相信伪sql会是:

select users.* from users where users.id is in (select distinct follower_id from followers where followers.user_id != 2)

!= 表示不同

答案 1 :(得分:0)

试一试:

Select users.* 
from users 
where users.id not in (
    select followers.follower_id 
    from followers 
    where followers.user_id = "2"
)