我试图对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 )
这是mi位置表
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
这是mi newLocations表
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.
答案 0 :(得分: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 。