Mysql ANY NOT EQUAL TO 子查询不工作

标签 mysql subquery

我在使用 ANY 进行查询时遇到了一个小问题。

Select *, count(*) as m 
from mp_bigrams_raw 
where date_parsed=051213 
and art_source='f' 
and bigram != ANY(select feed_source from mp_feed_sources) 
group by bigram 
order by m DESC 
limit 50;

查询运行但不排除在子查询中找到的项目。

子查询 中只有 1 行时,原始查询有效。一旦我添加更多,我就会收到关于超过 1 行的错误。

Select *, count(*) as m 
from mp_bigrams_raw 
where date_parsed=051213 
and art_source='f' 
and bigram != (select feed_source from mp_feed_sources) 
group by bigram 
order by m DESC 
limit 50;

从那里我添加了 ANY 并且查询运行但似乎忽略了 !=。我猜我在这里遗漏了一些东西。

谢谢

最佳答案

你为什么不使用 NOT IN

Select *, count(*) as m 
from mp_bigrams_raw 
where date_parsed=051213 
and art_source='f' 
and bigram NOT IN(select feed_source from mp_feed_sources) 
group by bigram 
order by m DESC 
limit 50;

关于Mysql ANY NOT EQUAL TO 子查询不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16507405/

相关文章:

mysql - 对 SQL count() 值进行计算

MySQL:批量插入的自动增量行总是具有相邻的ID吗?

mysql - 使用 SubQueries 查询 2 个表的总和

c# - 在 INSERT 查询中嵌套 SELECT

mysql - SQL——使用嵌套子查询进行计数

mysql - 如何改进 MySQL 中的 SELECT 子查询?

mysql - Over() 函数没有覆盖表中的所有行

mysql - 如何统计数据库每小时的行数?

mysql - 使用最近输入的值加入

CakePHP 和子选择