奇怪的事情发生了。我有安装在Windows NOT IN查询与我的MySQL社区服务器5.1中的问题。当我做这个查询:MySQL的 “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行
为什么最后一个查询不返回任何行?
** key **是SQL中的一个关键字尝试用反引号引用它 –
'some_key'可以为null吗? –
试试'where(date> =“2012-01-01”)和(key not in ...)'; MySQL的文档是含糊的'不in'操作和状态'EXPR NOT IN(值...)是一样的NOT(表达式IN(值,...))',这可能会导致'NOT( (日期> =“2012-01-01”和键)IN(...))'你的情况 – lanzz