简体   繁体   English

子查询返回的值超过1。 当子查询遵循> =或将子查询用作表达式时,不允许这样做

[英]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: 如果你满足于检查是否pkeytblAdr匹配任何的子查询中的值,那么你可以使用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.

相关问题 子查询返回超过 1 个值。 当子查询跟随......或当子查询用作表达式时,这是不允许的 - Subquery returned more than 1 value. This is not permitted when the subquery follows … or when the subquery is used as an expression 子查询返回的值超过1。 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =或用作表达式时,不允许使用 - Subquery returned more than 1 value. Not permitted when subquery follows =, !=, <, <= , >, >= or used as an expression 子查询返回的值超过1。 当子查询跟随=,!=时,不允许这样做, - Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, 子查询返回的值超过1。 当子查询遵循=,!=,&lt;, - Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, 子查询返回的值超过1。 当子查询遵循=,!=, - Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, 子查询返回超过 1 个值。 当子查询跟随 =, ,=, &lt;, &lt;=, &gt;, &gt;= 或 - Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or 子查询返回的值超过1。 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =…?时,不允许这样做。 - Subquery returned more than 1 value. This is not permitted when the subquery follows =,!=, <, <= , >, >= …? 子查询返回的值超过1。 当子查询遵循=时,这是不允许的 - Subquery returned more than 1 value. This is not permitted when the subquery follows = 子查询返回的值超过1。 当子查询跟随时,这是不允许的 - Subquery returned more than 1 value. This is not permitted when the subquery follows 子查询返回的值超过1。 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =时,不允许这样做 - Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >=
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM