[英]Subquery returned more than 1 value. This is not permitted when the subquery follows>= or when the subquery is used as an expression
Subquery returned more than 1 value error. 子查询返回了1个以上的值错误。 How to solve this? 如何解决呢?
SELECT top 1 address
FROM tblAdr A
WHERE A.pkey=
(SELECT b.pkey FROM tblMachine b WHERE b.ADDRESS_PKEY IS NULL
)
The subquery (the quantity in parentheses) is returning more than one pkey
value, which isn't allowed because a single scalar value is required. 子查询(括号中的数量)返回多个pkey
值,这是不允许的,因为需要单个标量值。 If you are content with checking whether a pkey
in tblAdr
matches any of the values in the subquery, then you can use WHERE A.pkey IN (...)
as follows: 如果你满足于检查是否pkey
在tblAdr
匹配任何的子查询中的值,那么你可以使用WHERE A.pkey IN (...)
如下所示:
SELECT TOP 1 address
FROM tblAdr A
WHERE A.pkey IN (SELECT b.pkey FROM tblMachine b WHERE b.ADDRESS_PKEY IS NULL)
Change the =
to an IN
将=
更改为IN
select top 1 address from tblAdr A where A.pkey in (select b.pkey from tblMachine b where b.ADDRESS_PKEY is null)
This should fix the error, however the logic of your query is likely flawed. 这应该可以修复错误,但是查询的逻辑可能存在缺陷。 You are after one row only ( select top 1
), however you don't define what row should be chosen first (no order by
clause). 您仅排在后面( select top 1
),但是您没有定义应该首先选择哪一行(没有order by
子句)。
Use IN
instead of =
as your subquery returns multiple matching rows. 使用IN
代替=
因为您的子查询返回多个匹配的行。
SELECT top 1 address
FROM tblAdr A
WHERE A.pkey IN
(SELECT b.pkey FROM tblMachine b WHERE b.ADDRESS_PKEY IS NULL
);
Also, always use top queries with order by. 另外,请始终将热门查询与order by一起使用。
此子查询“从tblMachine b中选择b.pkey,其中b.ADDRESS_PKEY为null”返回多个值,您无法将其与“ =”运算符进行比较,但您需要此try in子句
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.