“子查询返回的行数不正确”错误

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

我整夜都在网上搜索,试图找到答案。到目前为止,还没有运气。我尝试过的所有其他解决方案均导致语法错误。

我正在尝试运行一条update语句来更新选择项的location_id值。我有两个表:一个现有的INVENTORY表和一个TEMP_INV表,其中包含item_id值和新的location_id值的子集。我想用TEMP_INV表中的新location_id值更新INVENTORY表中的当前location_id值,但仅针对TEMP_INV表中的项目更新。

INVENTORY表格

item_id    location_id

123453     12-099
123454     12-100
123456     12-101
123457     12-102
123458     12-103

TEMP_INV表格

item_id    location_id

123456     13-101
123457     13-102
123458     13-103

所需结果:

INVENTORY表格

item_id    location_id

123453     12-099
123454     12-100
123456     13-101
123457     13-102
123458     13-103

我正在运行以下更新语句并收到错误“ 284:子查询返回的行不完全相同。”

UPDATE inventory
SET location_id =
(SELECT location_id
FROM temp_inv
WHERE item_id=item_id)
sql updates informix
1个回答
0
投票

使用连接查询:

UPDATE inventory i
INNER JOIN  temp_inv it
ON i.item_id    = it.item_id    
SET i.location_id= it.location_id;
© www.soinside.com 2019 - 2024. All rights reserved.