SQL:错误:用作表达式的子查询返回的行不止一行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3848679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL : ERROR: more than one row returned by a subquery used as an expression
提问by AnEventHorizon
The thing is that it does return one row.
问题是它确实返回了一行。
Here's the thing.
这是事情。
SELECT...
FROM...
WHERE...
GROUP BY...
HAVING randomNumber > (SELECT value FROM.....)
Whenever I have signs such as =, > it always returns me this error. When I do IN it doesn't.
每当我有诸如 =、> 之类的符号时,它总是会返回此错误。当我做 IN 它没有。
Are you not supposed to use comparison signs when comparing to another table?
与另一个表进行比较时,您不应该使用比较符号吗?
回答by Jonathan Leffler
When you type:
当你输入:
SomeValue IN (SELECT ...)
it is equivalent to using:
它相当于使用:
SomeValue = ANY (SELECT ...)
Don't use the second notation - but it illustrates a point. When the SELECT returns more than one value, you must use ANY or ALL with the comparator. When you omit ANY or ALL, then you must have a SELECT that returns exactly one value.
不要使用第二个符号 - 但它说明了一点。当 SELECT 返回多个值时,您必须将 ANY 或 ALL 与比较器一起使用。当您省略 ANY 或 ALL 时,您必须有一个只返回一个值的 SELECT。
回答by TheVillageIdiot
You can specify multiple values with IN
operator. If you are using >, = , <
etc. try using this:
您可以使用IN
运算符指定多个值。如果您正在使用>, = , <
等尝试使用这个:
HAVING randomNUmber > (SELECT MAX(value) FROM ......)