本文介绍了如何选择某个用户未加入Mysql的组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出三个数据表theUser
,theGroup
,membership
:
theUser:(*user_id*, username),
theGroup:(*group_id*, groupname),
membership:(*group_id*, *user_id*)
例如,组2
具有用户007
和008
,membership
应该类似于:
For instance, group 2
has user 007
and 008
, the membership
should be like:
group_id user_id
2 007
2 008
现在,我希望选择用户008
尚未加入的组.你能告诉我怎么做吗?提前致谢!
Now I wish to select the groups that user 008
HAS NOT BEEN IN. Could you tell me how to do that? Thanks in advance!
推荐答案
几种不同的方法可以做到这一点.这是带有outer join / null
支票的:
Several different ways to do this. Here's one with an outer join / null
check:
select g.*
from thegroup g
left join membership m on g.groupid = m.groupid and m.userid = '008'
where m.groupid is null
这篇关于如何选择某个用户未加入Mysql的组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!