假设我有一个频道成员表
channelID | accountID | role
------------------------
1 | Bob | 100
2 | Bob | 100
1 | Dave | 101
还有另一张频道表
channelID | channelName | type
---------------------------------------
1 | Public Channel | public
2 | Private Channel | private
我该如何获得用户不在公共频道中的频道?
我尝试这样做,但无法确定如何对channel members表进行分组,因为有两个channelID为1的项,所以当我使用用户Dave进行查询时,会得到channel 1,结果是channel1不应返回任何内容。我正在使用的查询:
Select ChatChannels.channelID, channelName, type
From ChatChannels
INNER JOIN ChatChannelMembers
On ChatChannels.channelID = ChatChannelMembers.channelID
Where AccountID = 'Dave'
最佳答案
这有用吗?
SELECT (stuff)
FROM ChatChannels CC
WHERE CC.type = 'Public'
AND CC.channelID NOT IN (SELECT channelID FROM ChatChannelMembers WHERE AccountID = 'Dave')
关于mysql - SQL检查组中是否存在值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40028319/