如何获取要关注的所有用户的列表

时间:2014-03-11 13:26:55

标签: sql sql-server database join

我有两个表USER和Relation_User如何列出我想跟踪他们的所有用户已经跟不上我

User Table

Usid|name
---------
1 | Jack
2 | Bla
3 | Havi
4 | Tri

Relation_User

Rid|usid|fusid
--------------
1 | 1 | 2
2 | 2 | 1
3 | 3 | 2
4 | 1 | 4

1 个答案:

答案 0 :(得分:0)

select usid, name from user u 
where u.usid <> @id and u.usid not in (
    select distinct fusid from relation_user where usid = @id
)
相关问题