2

我有两张表,成员和国家,我想做的是找到所有没有成员的国家。我有点迷路,这是我最好的猜测,但它不起作用:

SELECT CountryID
FROM Country 
WHERE (SELECT COUNT(MemberID) FROM Member WHERE PrCountryID = CountryID) = 0

任何帮助将不胜感激。

新杰克

4

3 回答 3

2
select countryID from Country C left join member M on C.CountryID=M.CountryID where M.MemberID is null
于 2012-11-13T16:56:33.317 回答
1

尝试使用not exists子句:

SELECT C.CountryID
FROM Country C
WHERE not exists(SELECT 1 FROM Member M WHERE M.PrCountryID = C.CountryID) 
于 2012-11-13T16:56:27.947 回答
0

在没有看到表格的情况下,我认为您需要这样的东西

select * from Country c
left outer join Member m on m.PrCountryID = c.CountryID
where m.PrCountryID is null
于 2012-11-13T16:59:02.963 回答