抱歉,我在这里更清楚地写了这个问题: How to get the nonmatching rows in 2 tables in SQL?
由于
答案 0 :(得分:3)
一个选项在65,9
和LEFT JOIN
表之间使用CHANNELS
:
SUBSCRIBERS
以下是合并期间中间表的外观:
SELECT c.ChanID, c.name
FROM CHANNELS c
LEFT JOIN SUBSCRIBERS s
ON c.ChanID = s.ChanID
WHERE s.ChanID IS NULL AND
c.nickname = 'Jonny' AND -- not sure about this condition
s.nickname = 'Jonny' -- or this one
答案 1 :(得分:0)
SELECT CHANNELS.ChanID FROM CHANNELS
LEFT JOIN SUBSCRIBERS ON CHANNELS.ChanID=SUBSCRIBERS.ChanID
WHERE
CHANNELS.type='public' AND
SUBSCRIBERS.nickname='a'
试试这个
编辑: 我没有正确地得到这个问题。如果要选择Jonny未订阅的行,请使用这样的子查询。
SELECT ChanID C FROM CHANNELS WHERE
(SELECT COUNT(*) FROM SUBSCRIBERS S WHERE S.ChanID=C.ChanID and S.nickname='Jonny') = 0
答案 2 :(得分:0)
select c.ChanID,C.name
from Channels c Left join subscribers s on
c.ChanID=s.ChanID
where s.ChanID is null
这应该有效,可能不需要其他条件。