奇怪的事情发生了。我在Windows上安装了MySQL Community Server 5.1,出现了一个问题,涉及到NOT IN查询。当我执行以下查询时:
select *
from table1
where date >= "2012-01-01";
返回582行
select *
from table1
where date >= "2012-01-01"
and the_key in (select some_key from table2);
返回 15 行
因此我期望以下查询将返回 582 - 15 = 567 行
select *
from table1
where date >= "2012-01-01"
and the_key not in (select some_key from table2);
返回0行
为什么最后一个查询没有返回任何行?
where (date >= "2012-01-01") and (key not in ...)
;MySQL文档对于not in
运算符并不明确,并且说明expr NOT IN (value,...)
与NOT (expr IN (value,...))
相同,这可能会导致在您的情况下出现NOT((date >= "2012-01-01" and key) IN (...))
。 - lanzz