284:子查询返回的不是一行

问题描述 投票:0回答:2

我正在尝试对 INFORMIX 中的表进行大量更新,但我的查询返回此错误:

284: A subquery has returned not exactly one row

这是我的询问:

update newLocations set
       description=
             (select unique b.description from newLocations a,locations b
             where a.id_location=b.id_location )

这是我的位置表

Table: locations        
id_location id2_location    description
02          AAA00           AS-LOC1 
05          AA000           AS-LOC2
10          AA010           AS-LOC7
20          AA020           AS-LOC8
30          AA030           AS-LOC9
40          AA040           AS-LOCA
50          AA050           AS-LOCB

这是我的新位置表

Table: newLocations     
id_location description
02          
05          
05          
05          
05          
05          
10          
20          
30          
40          
50          

我的子查询返回:

AS-LOC1 
AS-LOC2
AS-LOC7
AS-LOC8
AS-LOC9
AS-LOCA
AS-LOCB

如何在 newLocations 中分配描述,关联位置中的 id_location?

这就是解决方案,感谢 Joseph B

update newLocations 
  set description=
       (select max(l.description)
       from locations l
       where newLocations.id_location=l.id_location)
  where exists
  (select 1
   from locations l2
   where newLocations.id_location=l2.id_location);

这个错误:

 201: A syntax error has occurred.
sql informix
2个回答
4
投票

试试这个:

update newLocations nl
set description=
             (select MAX(l.description) 
              from locations l
              where nl.id_location=l.id_location )
where exists
(select 1 
from locations l2
where nl.id_location=l2.id_location);

这是使用 PostgreSQL 的 SQL Fiddle


0
投票

这是另一种可能的解决方案。

update newLocations nl
set description=
         (select l.description) 
          from locations l
          where nl.id_location=l.id_location l.rowid in 
(select min(l2.rowid) location l2 where nl.id_location=l2.id_location));
© www.soinside.com 2019 - 2024. All rights reserved.